Definition
Backtesting is the simulation of a trading strategy against historical market data to estimate the returns, risk, and behaviour it would have produced if deployed in the past. The output is a synthetic equity curve, a set of summary statistics — Sharpe ratio, maximum drawdown, hit rate, average win and loss — and a trade-by-trade log against which any later live performance can be compared.
Two architectural styles dominate. Vector backtesting operates on whole arrays of prices and signals at once using NumPy or pandas, producing a fast approximation suitable for early-stage factor research. Event-based backtesting advances time one bar or one tick at a time, exposing only past data at each step and routing simulated orders through a mock exchange that models latency, slippage, and partial fills. Event-based is slower but produces results closer to live trading.
Why it matters
How it works
The mechanics are deceptively simple — replay history, apply the strategy's rules, accumulate P&L — and the failure modes are subtle. Look-ahead bias sneaks in when a calculation uses information that would not have been available at the simulated timestamp, often through a poorly aligned data join. Survivorship bias appears when the universe contains only securities that still exist today, omitting the failures and delistings that would have hurt a real portfolio. Slippage and transaction cost assumptions, if too optimistic, can flatter a high-turnover strategy by hundreds of basis points a year. Overfitting is the deepest trap: with enough parameters and enough re-runs over the same data, a researcher can manufacture an arbitrarily attractive equity curve that will not survive contact with fresh data.
The defences are walk-forward analysis (parameters chosen on a rolling in-sample window, tested on the next out-of-sample window, advanced, repeated), proper out-of-sample holdouts that are touched only once, transaction-cost models calibrated to the strategy's expected fill venues, and a research log that records every experiment so the multiple-testing penalty for backtest-shopping can be honestly accounted for. Vector backtests are appropriate for fast factor screening and ranking ideas against one another; event-based backtests are mandatory before any strategy progresses to paper trading or live capital.