48 Hours
This assessment evaluates your ability to implement a systematic trading strategy backtester with proper state management, clean code architecture, and correct execution logic.
You will implement a 1-minute Moving Average (MA) Breakdown Short Strategy that simulates trades candle-by-candle using historical data.
- Source Code β Complete implementation in your preferred language (Python/JavaScript/Go (Python) recommended)
- Trade Log β CSV/JSON output of all executed trades
- Performance Report β Summary metrics (printed or in a separate file)
- README β Brief explanation of your approach and how to run the code
You will be provided with a CSV file containing 1-minute candle data:
timestamp,open,high,low,close,volume
2024-01-15 09:15:00,100.50,101.20,100.10,100.80,15000
2024-01-15 09:16:00,100.80,101.50,100.60,101.30,12000
...
- Simple Moving Average (SMA) β Period: 20 (default, should be configurable)
- Applied on closing price
Enter a SELL position when ALL conditions are met:
- Candle closes below the MA
- Distance between MA and close β₯ 5%
Formula:
(MA - Close) / MA β₯ 0.05
π Entry price = candle close
Once in a SELL position, calculate:
- Stop Loss (SL) = 10% above entry price
- Target (TG) = 20% below entry price
Formulas:
SL = Entry Γ 1.10
TG = Entry Γ 0.80
Exit the SELL position when any ONE of these occurs (first hit wins):
| Condition | Exit Reason |
|---|---|
| Price hits Stop Loss | STOP_LOSS |
| Price hits Target | TARGET |
| Candle closes above MA | MA_EXIT |
| End of trading day (15:30) | EOD_EXIT |
π Exit price = candle close (for MA_EXIT and EOD_EXIT)
After a position is exited, re-enter SELL when:
- Candle closes below the LOW of the exit candle
π Re-entry price = candle close
- Only one open position at a time
- Fixed quantity (assume 1 lot)
- No pyramiding
- No same-candle re-entries
- All decisions made on candle close only
Your output must include a trade log with the following structure:
entry_time | exit_time | side | entry_price | exit_price | pnl | exit_reason
Example:
entry_time,exit_time,side,entry_price,exit_price,pnl,exit_reason
2024-01-15 10:05:00,2024-01-15 10:45:00,SELL,98.50,78.80,19.70,TARGET
2024-01-15 11:20:00,2024-01-15 11:55:00,SELL,97.20,100.50,-3.30,MA_EXIT
Mandatory (must implement):
| Metric | Description |
|---|---|
| Total Trades | Number of completed trades |
| Win Rate | Percentage of profitable trades |
| Total PnL | Sum of all trade profits/losses |
| Max Drawdown | Largest peak-to-trough decline |
Bonus (optional):
- Expectancy per trade
- Average trade duration
- Profit factor
Your solution must:
- Simulate candle-by-candle (no vectorized lookhead)
- Prevent look-ahead bias (only use data available at current candle)
- Use close prices only for signal decisions
- Correctly maintain internal state:
- Active position flag
- Last exit candle low (for re-entry logic)
- Current SL / TG levels
| Criteria | Weight | Description |
|---|---|---|
| Correctness | 40% | Strategy logic matches specification exactly |
| Code Quality | 25% | Clean, readable, well-structured code |
| State Management | 20% | Proper handling of position states and transitions |
| Edge Cases | 10% | Handles gaps, partial data, EOD correctly |
| Documentation | 5% | Clear README and code comments |
- This is NOT a test of indicator creativity β follow the specification exactly
- Focus on correctness over optimization β working code beats fancy code
- Show your state machine logic clearly β this is what we're evaluating
- Handle edge cases gracefully β what happens at market open/close?
- Review this specification completely before coding
- Design your state machine first (diagram optional but recommended)
- Implement core logic
- Test with sample data
- Generate output and metrics
If any part of this specification is unclear, document your assumptions in the README and proceed. We value your problem-solving approach as much as the final output.
Good luck! π