iGainss

Why a backtest can fool you: overfitting, costs and survivorship bias

iGainss guide · November 16, 2026 · about 5 min read

A backtest runs a trading rule over past prices to see how it would have done. "Buy when the 50-day average crosses above the 200-day, sell when it crosses back below" can be tested over 20 years of history in a second. It is one of the most useful tools an investor has, and one of the easiest to be fooled by.

The problem is not the arithmetic. The problem is that the past only happened once, and with enough trying almost any rule can be made to look brilliant on it. This guide covers the main ways a backtest misleads and how to check yours.

1. Overfitting: trying until something works

Suppose you test a moving-average rule. It does not beat the market, so you try a 40-day average instead of 50. Then a 45-day. Then you add "only when RSI is below 60". Then a stop-loss at 8%. Eventually one combination looks great. Did you discover something, or did you just find the settings that happened to fit those particular years?

Usually the second. Every rule catches some real pattern plus some random noise. When you try hundreds of variations and keep the best, you are mostly selecting for the noise, and noise does not repeat. In 2014 the mathematicians David Bailey, Jonathan Borwein, Marcos López de Prado and Jim Zhu showed that impressive backtest performance is easy to reach after trying a relatively small number of configurations, and that the more configurations are tried, the more likely the winner is overfit. They argued that a backtest that does not say how many variations were tried cannot really be judged at all.

Signs of overfitting:

  • Oddly specific settings (a 47-day average, a 7.5% stop) that work while nearby settings do not.
  • Many conditions stacked together, each added to fix a bad period.
  • Great results on one stock or one period, and poor results on similar ones.
  • Very few trades. Five winning trades over ten years is not much evidence of anything.

2. Costs and taxes

Every trade costs something: a commission (often zero now), the spread between the buying and selling price, and for larger orders the price moving against you. A rule that trades often can see its whole edge disappear into those costs. In a taxable account, frequent selling also turns long-term gains into short-term gains, which in the US are usually taxed at a higher rate.

A good habit: rerun the test with a higher cost per trade than you expect. If a small change in cost wipes out the advantage, the advantage was thin to begin with.

3. Survivorship bias: testing only the winners

If you test a strategy on the companies in the S&P 500 today, you are testing on companies that survived and grew. The ones that went bankrupt, were bought out cheaply or shrank out of the index are missing. Any strategy looks better on a list of survivors.

This is a well-documented problem in investment research. A classic study of mutual funds by Edwin Elton, Martin Gruber and Christopher Blake (1996) noted that funds which disappear tend to do so because of poor performance, so studies using only surviving funds overstate how well funds do. The same logic applies to stocks: picking your test stocks with hindsight quietly builds that hindsight into the result.

4. Look-ahead bias: using information you would not have had

A backtest must only use what was known on each day. Common slips include trading at a day's closing price on a signal that needed that same close to calculate, or using a company's earnings figure from the date its fiscal quarter ended instead of the later date it was actually published. Each one makes the past look more predictable than it was.

5. One period is one story

A rule tested only from 2010 to 2020, mostly a long bull market, may simply be a bet that stocks go up. Check how the rule behaved through different conditions: a crash, a sideways market, a period of rising rates. Look at the maximum drawdown (the worst fall from a peak) too, not just the final value. A strategy that ends higher but falls 50% along the way is one most people would abandon at the worst moment.

A checklist before trusting a backtest

  • Compare with buy-and-hold of the same stock and with an index fund over the same period.
  • Count the trades. More trades means more evidence (and more costs).
  • Change the settings a little. A real effect should survive 45 or 55 days as well as 50.
  • Try other stocks and other years the rule was not designed on.
  • Raise the costs and see whether the edge survives.
  • Test it forward. Pick the rule today, then watch how it does on data that did not exist when you chose it. That is the only test that cannot be overfit.

How iGainss helps

The Strategy Tester runs a rule on real price history and reports the final value next to buy-and-hold and a benchmark (the S&P 500 by default), the number of trades, and the maximum drawdown. It charges a cost on every trade (0.1% by default, which you can raise) and lists every trade so you can see where the result came from. A forward test lets you save a rule today and check it later on prices that did not exist when you picked it.

RUN THEM ALL tests hundreds of variations on one stock and ranks them. Treat the top of that list with exactly the suspicion this guide describes: when hundreds are tried, the best one is the most likely to be luck. Use it to explore, then check the winner on other stocks, other years and forward.

Sources

Try it yourself: the Strategy TesterOpen the Strategy Tester

This guide is for education only and is not investment advice. Figures are worked examples, not forecasts. More guides

We use essential cookies for authentication and optional analytics cookies to improve the app. Privacy Policy