Skip to content

Instantly share code, notes, and snippets.

@ashavijit
Last active December 15, 2025 07:37
Show Gist options
  • Select an option

  • Save ashavijit/8a8fb95ca608318a7348a45623ccc2bf to your computer and use it in GitHub Desktop.

Select an option

Save ashavijit/8a8fb95ca608318a7348a45623ccc2bf to your computer and use it in GitHub Desktop.
assignment.md

πŸ“‹ Assessment

Trading Strategy Backtester Implementation


⏱️ Time Limit

48 Hours


πŸ“ Overview

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.


πŸ“¦ Deliverables

  1. Source Code β€” Complete implementation in your preferred language (Python/JavaScript/Go (Python) recommended)
  2. Trade Log β€” CSV/JSON output of all executed trades
  3. Performance Report β€” Summary metrics (printed or in a separate file)
  4. README β€” Brief explanation of your approach and how to run the code

πŸ“Š Sample Data

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
...

πŸ“‰ Strategy Specification

Indicator

  • Simple Moving Average (SMA) β€” Period: 20 (default, should be configurable)
  • Applied on closing price

1️⃣ Initial SELL (Short Entry)

Enter a SELL position when ALL conditions are met:

  1. Candle closes below the MA
  2. Distance between MA and close β‰₯ 5%

Formula:

(MA - Close) / MA β‰₯ 0.05

πŸ“Œ Entry price = candle close


2️⃣ Risk Management

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

3️⃣ Exit Conditions

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)


4️⃣ Re-SELL (Re-entry Logic)

After a position is exited, re-enter SELL when:

  • Candle closes below the LOW of the exit candle

πŸ“Œ Re-entry price = candle close

⚠️ Re-sell allowed only after an exit, not during an active trade.


Position Rules

  • 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

πŸ“‹ Trade Log Format

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

πŸ“ˆ Performance Metrics

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

βœ… Implementation Requirements

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

🎯 Evaluation Criteria

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

⚠️ Important Notes

  1. This is NOT a test of indicator creativity β€” follow the specification exactly
  2. Focus on correctness over optimization β€” working code beats fancy code
  3. Show your state machine logic clearly β€” this is what we're evaluating
  4. Handle edge cases gracefully β€” what happens at market open/close?

πŸš€ Getting Started

  1. Review this specification completely before coding
  2. Design your state machine first (diagram optional but recommended)
  3. Implement core logic
  4. Test with sample data
  5. Generate output and metrics

❓ Questions?

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! πŸ€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment