What is a backtest?

A backtest runs a fixed set of trading rules over past prices to see how they would have done.

A good backtest counts costs and avoids using information that was not known on the day. Past results do not promise future ones.

It has four steps: write exact rules for entry, exit and position size; run them over many years of data; record every trade; then measure the results.

Example

A rule such as “enter when a share closes above its 200-day average and exit when it closes below” can be run over 20 years of NSE prices to count the trades, the share that made money and the largest fall on the way.

Good to know

  • Common measures are CAGR, the win rate, the profit factor and the maximum drawdown (the largest fall from a peak).
  • Look-ahead bias is using data that was not yet known on the trade date.
  • Survivorship bias is testing only on companies that exist today and leaving out those that failed or delisted.
  • Overfitting is tuning the rules until they fit the past so well that they fail on new data.

Common questions

Does a good backtest mean a strategy will work?

No. It shows the rules worked on past data under the test’s assumptions. Markets change, and live trading adds costs and delays a test can miss.

What is out-of-sample testing?

Keeping a part of the data aside, building the rules on the rest, and then testing them once on the part kept aside. It is a guard against overfitting.

What costs does a backtest need to count?

Brokerage, taxes and charges on each trade, and slippage: the gap between the price the rule assumes and the price actually got.

For learning only: not advice to invest in anything. Every word in the glossary.