Backtesting is the process of applying a fixed set of trading or investment rules to historical market data to see how that rule would have performed before any real money is committed.
How it works
A backtest has four parts: a precisely stated rule (entry, exit and position sizing), a historical data set, a simulation engine that steps through time, and a set of performance measures. The simulator should only use information that was available on each historical date, and it should charge the costs a real investor would pay. The output is typically an equity curve with annual return, volatility, maximum drawdown and a risk-adjusted measure such as the Sharpe ratio.
Backtesting answers the question 'what would this rule have done?' It cannot tell you what the rule will do. Past data is one sample of market behaviour, and the future may look different.
Worked example
Suppose a rule holds a broad equity index when its price closes above its 200-day moving average, and holds cash otherwise. Using hypothetical data over ten years, the starting value is 10,000 units.
- Gross result: the rule grows to 16,500 units, compared with 15,000 units for holding the index throughout.
- Costs: the rule trades 40 times over the decade. If each trade costs 0.1% of the amount traded, and the portfolio is about 10,000 units, each trade costs roughly 10 units, or about 400 units in total.
- Net result: about 16,100 units, still ahead of simple holding in this illustration.
The lesson is not that the rule works. The result depends on one data set, one period and one set of assumptions. Changing the moving average to 180 or 220 days might reverse the ranking, and that sensitivity is itself important information.
Why it matters to investors
Backtesting is useful for filtering ideas. A rule that loses money even before costs over a long and varied history is unlikely to be robust. It also shows what a strategy has historically felt like, including deep drawdowns, long stretches of underperformance and how often it trades. That experience matters, because investor behaviour often breaks a strategy before the numbers do.
The real danger is false confidence. A smooth, rising equity curve can be produced by mistakes in the test itself, which is why careful design matters more than the size of the apparent return.
Common mistakes
Overfitting
Overfitting happens when a rule is tuned so closely to past noise that it captures coincidences rather than repeatable patterns. With enough parameters, almost any history can be fitted. A warning sign is a rule with many thresholds that works well only at one exact setting. Out-of-sample testing, where parameters are chosen on one period and checked on a later period never used for tuning, is the standard safeguard.
Look-ahead bias
Look-ahead bias occurs when the test uses information that was not known at the time of the decision. Examples include using a company's annual earnings before they were published, or triggering a trade at the same closing price that generated the signal. Every signal should be lagged to the moment it would actually have been observable.
Survivorship bias
Survivorship bias occurs when the data set includes only assets that still exist today. Companies that failed, were delisted or were merged away are missing, so the historical universe looks better than it was. A test of 'the largest companies' built from today's list quietly selects past winners. Point-in-time data, which includes securities as they existed on each historical date, reduces this problem.
Transaction costs and frictions
Many simple backtests ignore costs. Brokerage, taxes where relevant, bid-ask spreads, slippage and market impact all reduce results, and they compound with trading frequency. A rule that trades daily can look profitable on paper and lose money after realistic costs. Costs should be modelled conservatively, and the sensitivity of results to them should be tested.
Other pitfalls
Short histories may contain only one market regime. Unadjusted prices after a stock split or a dividend can create false signals. Changing the rule after seeing its results is a form of overfitting, even when no formal optimiser was used.
What to watch out for
Ask whether the rule was defined before the test, whether the data is point-in-time, whether costs are realistic and whether the result holds on data that was not used to design the rule. A backtest that passes these checks is still only evidence, not proof.
Related concepts
Useful companion ideas include the Sharpe ratio for risk-adjusted return, drawdown for measuring peak-to-trough losses, slippage for the gap between expected and actual execution prices, volatility for how much returns fluctuate, and the benchmark index against which any rule should be compared.