Implementing a backtesting engine in Python
This easy coding problem asks you to build the core loop of a quantitative trading backtest: processing a stream of price data, executing trades according to a strategy function, and tracking two hard constraints—maximum drawdown and position size limits.
The problem tests your ability to manage state across multiple timesteps, handle account value and position tracking accurately, and enforce stopping conditions correctly. You'll need to distinguish between violations that halt all trading permanently (drawdown) and those that only restrict future trades (position limits), while correctly recording when each violation occurs and when a position constraint is lifted.
- Position and cash accounting across trades
- Conditional trade execution based on constraint state
- Rounding financial values to two decimal places
- Distinguishing violation types and their implications for future trading