Backtesting means writing down a strategy as exact rules, then applying those rules to past market data to see what would have happened: the trades, the returns, the losses along the way. It turns a vague idea (“buy when RSI is low”) into something that can be measured.
Today anyone can backtest. Spreadsheets, free coding libraries in Python and R, charting platforms and AI coding assistants make it possible to test an idea in minutes. That is powerful, but it also makes it easy to produce results that look impressive and mean little. A backtest is evidence, not proof.
The steps of a sound backtest
- Write precise rules before looking at results: what you buy, when, how much, when you sell, and what you do with cash.
- Use clean, complete data, including companies that were later delisted or went bankrupt, and prices adjusted for splits and dividends.
- Include realistic costs: commissions, the bid-ask spread, slippage, taxes and borrowing costs for short positions.
- Split the data: develop the idea on one period (in-sample) and test it once on a period you have not touched (out-of-sample).
- Measure risk, not just return: maximum drawdown, volatility, the Sharpe ratio, the number of trades and the longest losing streak.
- Compare with a simple benchmark, such as buying and holding an index fund. Many strategies fail to beat it after costs.
What a backtest can tell you
A careful backtest shows whether an idea had any measurable effect in the past, how large the losses along the way were, and how sensitive results are to small changes in the rules. If a strategy only works with one exact setting, it is probably fitted to noise.
What it cannot tell you
Markets change. Rules that worked in one regime (falling interest rates, for example) may not work in another, and once a pattern is widely known, trading can erase it. A backtest also cannot capture how you will feel and behave during a real drawdown. See the common backtesting biases before trusting any result.
Going further
Walk-forward testing repeats the develop-then-test process across many rolling periods. Paper trading runs the rules in real time without money. Monte Carlo simulation shows the range of outcomes the same strategy might produce.
A worked example
Worked example
A rule says: hold a broad index fund when its price is above its 200-day moving average, otherwise hold cash. Suppose a backtest over 25 years shows an annual return of 7.2% against 8.0% for always holding the fund, but a maximum drawdown of 22% instead of 50%.
Adding realistic costs, 0.1% per trade and around 40 switches, lowers the rule’s return to about 7.0%. Testing the same rule on another market and on a different period shows smaller drawdown benefits. The honest conclusion: the rule reduced deep falls in the test data at the cost of some return, and that trade-off may not repeat.
Common mistakes
- Using only one market or one period.
- Forgetting costs, slippage and taxes.
- Optimising parameters until the past looks perfect.
Frequently asked questions
Is a profitable backtest enough to trade a strategy?
No. It is a starting point. Out-of-sample testing, realistic costs, a check for biases and a period of paper trading are usually needed before risking real money, and even then past results do not guarantee future ones.
How much data do I need for a backtest?
Enough to include different market conditions, such as rising and falling markets and periods of high and low volatility, and enough trades that the results are not down to a handful of lucky ones.
Related
More modern tools & methods
- Backtesting
- Backtesting Biases
- Monte Carlo Simulation
- Factor Models
- AI in Investing
- Alternative Data
- Algorithmic Trading
- Screeners, Data Sources & Robo-Advisers
Indicators describe what prices have done; none of them predicts what prices will do. Charts use an illustrative price series, not real market data. This page is education, not investment advice.