/ docs / src / engine / engine_notes.md
engine_notes.md
 1  # Backtesting overview
 2  
 3  ## Goals
 4  
 5  - The backtest should be able to be executed given a custom start and end date.
 6  - The strategy has to have access to the OHLCV and all past trade history.
 7  - It must be able to run during live trading.
 8  
 9  ## Main loop
10  
11  - for each `timestamp`:
12    - while true:
13      - process(`[strategy](../guides/strategy-development.md)`, `timestamp`, `context`)
14      
15  The loop is just a timestamp feeder!, and the [strategy](../guides/strategy-development.md) holds all the state.
16  
17  - Because we use the `TimeFrames` abstraction, the step can be arbitrary, the strategy will just index into ohlcv data according to the last candle compatible with the given timestamp. This is a performance trade-off, we prefer to always index with dates, and never with integers, because it reduces the assumptions to _the row data must match its timestamp_ (its not corrupted!) compared to spurious bugs that might arise by integer indexing.
18  - The simulation is adversarial to the strategy, it is the job of the simulation to decide __how much__ loss a trade has incurred.
19  
20  ## Strategy General Considerations
21  
22  - The strategy must account for a  tie breaker to choose which trades to perform on the same candle since we don't know which pair we observed first. In general this is a good use case for MC.
23  
24  
25  ## See Also
26  
27  - **[Optimization](../optimization.md)** - Performance optimization techniques
28  - **[Performance Issues](../troubleshooting/performance-issues.md)** - Troubleshooting: Performance optimization techniques
29  - **[Data Management](../guides/data-management.md)** - Guide: Data handling and management
30  - **[Exchanges](../exchanges.md)** - Data handling and management
31  - **[Strategy Development](../guides/strategy-development.md)** - Guide: Strategy development and implementation
32  - **[Optimization](../optimization.md)** - Strategy development and implementation
33  
34  ## What does executing an order mean?
35  When the engine executes an order, it does the following for every order:
36  - Decide if order should be honored or fail
37  - Perform simulations, like spread, slippage, market impact.
38  - Signal to the strategy about failed (canceled) orders.