Home › Blog › Research
Research

Backtesting Mistakes: Overfitting, Look-Ahead Bias and Hidden Costs

By Contraday··8 min read

The errors that make a backtest look far better than real trading will be: curve fitting, look-ahead bias, survivorship, ignoring costs and testing on too little data, and how to avoid each one.

Cloud computing in enabling data science at scale
Photo: Srv Ganesh, CC BY-SA 4.0, via Wikimedia Commons.

Key takeaways

  • A backtest removes bad ideas; it does not prove good ones.
  • Overfitting and look-ahead bias inflate results.
  • Include realistic costs and check drawdown.
  • Test on data you did not use to build the rules.

What a backtest can and cannot do

A backtest applies a fixed set of rules to historical data to see how they would have performed. It can show that an idea is clearly not working, and it can show how large the losses and drawdowns might be. It cannot prove that the future will look like the past. The goal is to remove bad ideas cheaply, not to find a guaranteed winner.

1. Overfitting (curve fitting)

If you tune enough parameters, such as entry time, stop size, indicator period and filters, you can make almost any dataset look profitable. The result is a strategy that fits the noise of the past and falls apart on new data. Warning signs: very many parameters, very precise values (a stop of 17.3 points), and results that collapse when you change a number slightly. Prefer simple rules and check that nearby settings also work.

2. Look-ahead bias

This happens when the test uses information that was not available at the time of the trade, for example using the day's closing price to decide a morning entry, or the day's high and low to place a stop. It produces unrealistically good results. Always ask: at the exact moment of the decision, would I have known this?

3. Ignoring costs and slippage

Brokerage, taxes, exchange fees and the gap between the price you expected and the price you got can turn a small edge into a loss. Options add another issue: wide bid-ask spreads and thin strikes. Include realistic costs, and be sceptical of any strategy whose profit per trade is smaller than those costs.

4. Too little data, one market regime

A test over a few months, or only over a rising market, tells you very little. Use as many sessions as possible, covering trending, sideways, calm and volatile periods. Look at the maximum drawdown and the longest losing streak, not just the final profit, because that is the part you must live through.

5. Survivorship and data quality

Test data should reflect what really traded. Missing candles, wrong expiries and adjusted prices can all distort results. For options, expired contracts matter: our Backtest Tool rebuilds ATM straddles from expired-option candles for this reason.

A safer workflow

  1. Write the rules in plain words before testing.
  2. Split the data: build on one period, then check on a separate period you have not touched.
  3. Add realistic costs.
  4. Look at drawdown, not only returns.
  5. Paper-trade the rules, see paper trading before going live.
  6. Go live with small size and compare real results with the backtest.

Walk-forward testing and out-of-sample data

The most practical defence against overfitting is to test on data that played no part in building the rules. Divide history into sections: design the strategy on the first part (in-sample), then run it unchanged on the later part (out-of-sample). A more thorough version is walk-forward testing: optimise on one window, test on the next, then roll the windows forward and repeat. If the results hold across several windows, you have more reason to trust the idea. If performance is excellent in-sample and poor out-of-sample, the strategy has probably learned noise. Resist the temptation to adjust the rules after seeing the out-of-sample result, because that turns it back into in-sample data.

Reading the report, not just the profit

A backtest report has more useful numbers than the final profit: the number of trades, win rate, average win and loss, maximum drawdown, the longest losing streak and the profit factor (gross profit divided by gross loss). A strategy that earns a decent profit with a deep drawdown may be impossible to follow in real life. Check also how much of the total profit came from a handful of trades; if removing the best three trades turns the result negative, the edge is fragile. Compare results across different years and market conditions to see where it works and where it struggles.

From backtest to live: expect degradation

Live results are usually worse than backtests. Fills are worse, data has gaps, rules are applied late, and emotions interfere. Plan for this. Expect a smaller edge than the test showed, start with small size, and compare live metrics with the backtest over the first fifty trades or so. If the live results are far outside what the test suggested, stop and investigate rather than increasing size. A trading journal makes this comparison possible, and paper trading catches many execution problems before they cost real money.

Questions to ask of any backtest result

  • How many trades does the result contain, and over how many years?
  • Were costs and slippage included at realistic levels?
  • How many parameters were tuned, and did nearby values work too?
  • What was the maximum drawdown and the longest losing streak?
  • How does the result look in the worst year, not only the best?
  • Would I have been able to place these exact orders in real time?

If you cannot answer most of these, treat the result as a clue, not as proof. Strong results that survive these questions are rarer than they look, which is why a careful, sceptical process is the best protection against costly surprises later.

Try it yourself — free tools

Frequently asked questions

What is overfitting in backtesting?

Tuning a strategy so closely to past data that it captures random noise instead of a real edge, so it performs poorly on new data.

What is look-ahead bias?

Using information in a test that would not have been available at the time of the trade, which makes results look better than they could be in live trading.

How much data do I need for a reliable backtest?

As much as practical, spanning different market conditions. A few months of one kind of market is rarely enough.

Educational content, not investment advice. Trading in options involves substantial risk of loss. Backtested or hypothetical results are not live results and past performance does not guarantee future returns.

Related reading