Backtesting is testing a trading strategy on historical data, applying its exact rules as if you had traded in the past, to see how it might have performed.
In short
- Shows how rules would have behaved, not how they will behave.
- Needs realistic costs, slippage and clean data.
- Biases such as overfitting, look-ahead and survivorship bias can make results look far too good.
- Out-of-sample and forward testing are essential next steps.
How it works
Backtesting means applying a set of trading rules to historical price data to see how the strategy would have performed. It is the closest thing traders have to a laboratory experiment, but only if it is done carefully.
The process starts with rules precise enough for a computer, or another person, to follow without judgement: exactly when to enter, where to place the stop, how to size the position and when to exit. Vague rules such as 'buy strong stocks' cannot be tested. Next comes clean data: prices adjusted for splits and dividends, and, for stocks, including companies that were later delisted.
The strategy is then run through the data, trade by trade, recording each result. The output usually includes total and annualised return, win rate, average win and loss, expectancy, maximum drawdown, the longest losing streak and risk-adjusted measures such as the Sharpe ratio. Realistic trading costs (commissions, spreads, slippage and taxes) must be included, because they can turn a profitable-looking system into a losing one.
Several common errors make backtests look far better than reality. Look-ahead bias uses information that wasn't available at the time, such as trading on a day's close using that same close. Survivorship bias tests only stocks that still exist, ignoring those that went bust. Overfitting (curve fitting) tunes so many parameters that the strategy describes the past perfectly but has no edge going forward.
To guard against overfitting, traders split data into an in-sample period, used to design the strategy, and an out-of-sample period, kept aside to test it once. Walk-forward analysis repeats this process across rolling windows. Simple rules with few parameters, which work across different markets and periods, are generally more believable than complex ones tuned to a single history.
Even a careful backtest is only evidence, not proof. Markets change, so the usual next steps are forward testing on live data with paper or small real positions, and comparing live results with the backtest.
An example with numbers
Example 1: A moving-average crossover on an index shows 14% a year from 2000 to 2020 before costs. After adding commissions and slippage, it drops to 9%. Testing 2021–2024 (out of sample) gives 4%.
Example 2 (look-ahead bias): A backtest buys at the day's close when the close is above its average, but in reality you only know the close after it happens. Trades should be executed at the next open instead.
Example 3 (survivorship): Testing a stock strategy only on today's index members ignores companies that went bankrupt, inflating results.
How it differs by market
| Market | What to know |
|---|---|
| India | Backtests should include STT, exchange charges, GST, stamp duty and SEBI fees, which can be large for high-frequency F&O strategies. |
| United States | Survivorship-bias-free datasets (including delisted stocks) are available from data vendors and academic sources such as CRSP. |
| Global | Corporate actions such as splits and dividends must be adjusted correctly in any market. |
Where people go wrong
- Optimising until the backtest looks perfect (overfitting).
- Ignoring costs and slippage.
- Testing on too short or too specific a period.
Common questions
What is backtesting in simple words?
Checking how a trading strategy would have performed in the past by applying its rules to historical data.
Does a good backtest mean the strategy will work?
No. It's a necessary first filter, not a guarantee. Biases and changing markets often reduce live results.
How many years should I backtest?
Enough to include different market conditions, such as bull, bear and sideways phases, and enough trades to be statistically meaningful.
What software can I use?
Platforms like TradingView, Amibroker and MetaTrader, or programming languages like Python with backtesting libraries.
What is forward testing?
Running the strategy in real time on paper or with small money to check it behaves as the backtest suggested.