Glossary
Backtesting
Testing a trading rule on historical data to see how it would have performed, before risking money on it.
On this page
Backtesting is the process of applying a precisely defined trading or investing rule to historical market data to estimate how it would have performed. It turns an idea such as "buy when the 50-day average crosses above the 200-day" into numbers: total return, win rate, average gain and loss, and the worst drawdown. A backtest is a cheap way to reject a bad idea before it costs real money, but a good backtest is far from proof that a strategy will work.
How it works
- Write the rules so that a computer could follow them with no judgment: entry, exit, position size and which securities qualify.
- Run them bar by bar over past data, using only information available at each point in time.
- Subtract realistic costs: commissions, the bid-ask spread and slippage.
- Measure results and compare them with simply holding a benchmark.
Common traps
- Overfitting. Tuning parameters until the past looks perfect captures noise. A strategy with many knobs almost always backtests well and trades badly.
- Look-ahead bias. Using data that was not yet known, such as a day's closing price to trade at that day's open, or later-revised earnings.
- Survivorship bias. Testing only companies that exist today leaves out the ones that went bankrupt or were delisted.
- Too few trades or one market regime. Twenty trades in a rising market prove little.
Safeguards include holding back an out-of-sample period, walk-forward testing and then paper trading before using real money.