No Session Today
View all rates
Intermediate3 min readTrading and Investing Strategies · 10/10

Backtesting: How to Test a Strategy on Past Data

Before putting money behind a rule, you can ask: had I applied exactly this rule over past years, what would have happened? That is a backtest. It shows you important things, and it fools you easily if you are careless.

What you will learn

  • Know the steps of a backtest and the figures it produces.
  • Understand why you must test on a period not used to build the rule.
  • Recognise four common errors that flatter the result.
In this lesson

The steps

  1. Write the whole ruleEntry, exit, position size and which stocks. It must be clear enough that anyone applying it gets the same trades.
  2. Apply it to past dataDay by day, using only what was known on that day.
  3. Read the figuresThe return, the largest peak-to-trough drawdown, the number of trades and the share of winning trades.

The maximum drawdown matters as much as the return. A rule that made a lot but fell 40% along the way is often hard to stick with in practice, because many people abandon it midway.

A period to build, a period to test

Build period2018…2023
Test period2024…2025
Build result+90%Max drawdown −18%
Test result+6%Max drawdown −27%
Invented figures: a rule tuned on 2018 to 2023 looks excellent, and on a new period the result is very different.
ExampleSomeone tries 50 moving-average settings on 2018 to 2023 data and picks the top one, which shows +90%. Applying exactly the same settings to 2024 and 2025, which were not used in the choice, gives only +6%, and the maximum drawdown grows from −18% to −27%. The first figure was inflated because it was picked from 50 attempts on the same data.

Four common errors that flatter the result

Over-fittingTailoring the rule to old data until it memorises it instead of capturing anything general.
Look-ahead biasUsing a figure not known at decision time, such as the closing price for an intraday decision, or results published later.
Survivorship biasTesting the past with today's list of stocks, which leaves out the companies that existed then and were later delisted or disappeared. A sound test uses the stocks that were actually available on each date.
Ignoring costsCommissions, the bid-ask spread, and the difficulty of filling orders in thinly traded stocks.
Watch outA successful backtest means the rule would have worked in the past under the conditions tested; it is no guarantee it will work from now on. Markets change, and a result that looks too good may be a sign of one of the errors above, so check it before you believe it.

Try a rule yourself

Open the backtest page, try a simple rule on two different periods, and compare the return and maximum drawdown between them.

Check yourself

1. Why test the rule on a period not used to build it?

A separate period exposes over-fitting.

2. A rule decides at 11 a.m. using that day's closing price. What error is this?

The closing price was not known at 11.

Summary

  • A backtest applies a fully written rule to past data and measures return, maximum drawdown and trade count.
  • Always test on a separate period not used to build the rule.
  • Over-fitting, look-ahead bias, survivorship bias and ignoring costs make results look better than reality.

Related terms

Related lessons

Educational content only, not investment advice. Companies and figures in the examples are invented for illustration.