What to Pay Attention to When Backtesting
Capital Based Backtesting Mathematical Model
Constants: Commission
Parameters: Money, Limit order target(+%), Stop order target(-%)
Outputs: Minimum Success Rate expected for the Trading Strategy
Analyzed values: Bid-Ask list in the orderbook for each coin
Here are the key points to consider for an effective and reliable backtest:
1. Data Quality
1.1. Detecting Data Errors
Missing, incorrect, or anomalous "spike" data can severely distort results. Always clean and validate your dataset before running any tests.
1.2. Using Realistic Data
Whenever possible, use datasets that include trading volume, spreads (bid-ask differences), and trading fees to achieve more realistic outcomes.
1.3. Time Synchronization
If you're working with multiple assets or timeframes, make sure all timestamps are properly aligned.
2. Avoiding Look-Ahead Bias
Make sure your strategy does not use information that would not have been available at the time of decision-making.
For example, if your strategy reacts to the closing price of a candle, it must wait for that candle to close before acting.
3. Overfitting Risks
Overfitting a strategy to historical data (also called curve fitting) often leads to poor performance in live markets.
Keep your strategy simple and avoid adding too many rules or parameters just to improve past results.
4. Realistic Order Execution Modeling
4.1. Spread and Slippage Effects
Orders may not always be filled at the desired price.
Incorporate spread and slippage assumptions into your model to simulate real-world execution more accurately.
4.2. Order Book Depth
If your strategy involves large trade sizes, consider whether the market has enough liquidity to absorb your orders without significant price impact.
5. Accounting for Fees and Costs
Every trade involves costs such as commissions, spreads, and sometimes taxes.
Ignoring these can falsely inflate a strategy’s profitability.
6. Out-of-Sample Testing and Walk-Forward Analysis
6.1. Out-of-Sample Testing
Test your strategy on data that was not used during the development phase to verify its robustness.
6.2. Walk-Forward Analysis
Optimize your strategy on a certain period, then immediately test it on the next period, repeating this process sequentially.
This method better simulates real-world trading conditions.
7. Position Sizing and Risk Management
Don't just focus on returns—evaluate the risk profile of the strategy as well. Important metrics include:
Maximum drawdown
Position sizing rules
Expected return per unit of risk
8. Choosing the Right Timeframe
The timeframe of your data (e.g., 1-minute, hourly, daily) significantly affects strategy behavior.
Lower timeframes tend to be noisier and require different handling compared to higher timeframes.
9. Considering Real-World Conditions
Markets are not always ideal.
Unexpected news events, liquidity shocks, and price gaps can heavily impact real-world trading performance and should be considered during backtesting.
10. Testing Psychological Resilience
It's not enough for a strategy to generate high returns historically.
Ask yourself:
Can the strategy survive long periods of drawdown?
Will you be able to stick to it emotionally during difficult times?
The emotional side of trading is just as important as the mathematical side when assessing a strategy's viability.