Backtesting

A backtest runs a defined trading rule over historical data. It answers what the simulation would have done under its assumptions, rather than what a live trader certainly would have achieved.

Define the rule first

Specify the signal, available information, order timing, position limits and exit conditions. Record parameter choices and the reason for each change. If rules change after seeing results, that run has also become part of the research process.

Time and leakage

Use only information available when the simulated decision occurs. A timestamp can refer to the period a value describes rather than when it was published. A revised dataset may contain information absent from its original release.

Fit preprocessing and models on the training period. Evaluate on later periods, using a gap where overlapping observations would otherwise share information. See TimeSeriesSplit for chronological splitting.

Execution assumptions

Include spread, fees, slippage and relevant funding costs. A limit price appearing in the data does not establish that your order would have filled. A midpoint fill can be especially optimistic for a strategy supplying liquidity.

Model latency and partial fills where they affect the result. Check that an order can be submitted before the price at which the simulation fills it is observed.

A three-clock design

Give each event a market time, arrival time and decision time. Market time records when the event happened. Arrival time records when the simulated strategy received it. Decision time records when the resulting action was ready to send.

Keep the event queue ordered by arrival and delivery rules. A strategy may use only events already delivered to it. Keep execution separate so changing the assumed latency does not silently change the signal calculation.

Reading the result

Report total return, drawdown, turnover, exposure and the distribution of trade outcomes. Show costs separately. Keep periods with no trading and failed executions in the record.

Compare with a simple baseline. Check whether small parameter changes or another time period destroy the result. Repeatedly selecting the best result from many variants can fit noise.

See Risk and Position Sizing and Market Simulator for the account and execution components.