Grizzly Bulls Research

Overfitting in Algorithmic Trading: How Good Backtests Go Bad

A trading strategy can look brilliant in historical data and still fail live because the research process selected noise. Learn how backtest overfitting happens, why ordinary train/test splits can mislead, and how to design harder tests.

By Lee BaileyPublished Updated
Overfitting in Algorithmic Trading: How Good Backtests Go Bad

A backtest can be accurate and still be useless.

That sounds contradictory, but it is the central problem with overfitting. The code may correctly calculate every trade that a strategy would have made on historical data. The problem is that the strategy itself may have been selected because it happened to fit that particular history unusually well.

If you test enough indicators, lookback windows, thresholds, filters, markets, start dates, and combinations, something will eventually look exceptional. The winning backtest can be the financial equivalent of finding a face in a cloud.

Overfitting is a research-process problem

Overfitting is often described as a model being "too complex." Complexity can increase the risk, but it is not the full story.

Imagine testing 10,000 simple strategies and publishing only the one with the highest Sharpe ratio. Even if every strategy is built from noise, the best result will probably look much better than average. The selection process itself created a bias.

This is why a clean in-sample equity curve is weak evidence by itself. The important questions are:

  • How many ideas and parameter combinations were tried?
  • How much of the history influenced the final design?
  • Was the "out-of-sample" period truly untouched?
  • Does performance survive reasonable changes in parameters and assumptions?
  • Does the strategy work across more than one favorable market regime?
  • Are transaction costs, slippage, spreads, borrow costs, and execution constraints realistic?

Researchers David Bailey, Jonathan Borwein, Marcos López de Prado, and Qiji Jim Zhu formalized this problem as the probability of backtest overfitting. Their work focuses on the risk that the best strategy selected from many historical trials will disappoint out of sample. (The Probability of Backtest Overfitting)

A related problem appears throughout empirical finance. Campbell Harvey, Yan Liu, and Heqing Zhu showed why testing hundreds of candidate factors makes ordinary significance thresholds too permissive. The more hypotheses you try, the more false discoveries you should expect. (... and the Cross-Section of Expected Returns)

The most common ways a trading backtest gets overfit

1. Searching too many parameter combinations

Suppose a moving-average strategy has two lookback periods. Testing 10 combinations is one thing. Testing every short window from 2 to 100 days against every long window from 20 to 400 days creates thousands of chances to find a lucky pair.

The danger is highest when the researcher reports only the winner and forgets how many losers were required to find it.

A stronger strategy usually has a parameter plateau rather than one magical setting. If 49/201 works brilliantly while 48/201, 50/201, and 49/200 collapse, the backtest is telling you that the result may depend on noise.

2. Reusing the test set

A common workflow is:

  1. build on training data;
  2. check the strategy on a test period;
  3. dislike the result;
  4. change the strategy;
  5. check the same test period again.

After enough rounds, that test period is no longer out of sample. It has become part of the research process.

This is one of the easiest mistakes to make because no individual adjustment feels like cheating. The contamination happens gradually.

3. Randomly shuffling financial time series

Ordinary machine-learning cross-validation often assumes observations can be shuffled freely. Market data has time order, serial dependence, regime changes, and overlapping labels.

A model trained using information from 2025 should not be used to validate a prediction supposedly made in 2022.

For many trading problems, chronological splits, rolling windows, walk-forward tests, or more specialized financial cross-validation methods are more appropriate than random k-fold validation.

4. Ignoring trading frictions

A signal can disappear after adding realistic costs.

That includes more than commissions. Depending on the strategy, the important frictions may include bid-ask spread, market impact, slippage, borrow fees, financing costs, option spreads, contract rolls, taxes, or the fact that a historical closing price was not actually executable at size.

A good robustness test makes these assumptions somewhat worse and asks whether the strategy still has an edge.

5. Tuning to one market regime

A strategy discovered during a persistent bull market may simply be a disguised long-beta trade. A mean-reversion strategy discovered during a range-bound period may fail when trends become persistent.

Break the history into economically different periods. Look at inflationary and disinflationary regimes, calm and volatile markets, bull and bear periods, and different interest-rate environments where relevant.

The goal is not to demand identical performance everywhere. It is to understand what risk the strategy is actually taking.

A better validation stack

There is no single test that proves a trading strategy is real. The defense is a stack of harder tests.

Keep a research log

Record every meaningful strategy family and parameter search, including failures.

This sounds mundane, but it solves an important statistical problem. If you remember only the final backtest, you will underestimate how much searching produced it.

Split data in time order

A basic walk-forward structure looks like this:

javascript
1function walkForwardSplits(rows, trainSize, testSize) {
2  const splits = [];
3
4  for (
5    let testStart = trainSize;
6    testStart + testSize <= rows.length;
7    testStart += testSize
8  ) {
9    splits.push({
10      train: rows.slice(testStart - trainSize, testStart),
11      test: rows.slice(testStart, testStart + testSize),
12    });
13  }
14
15  return splits;
16}

This code does not solve overfitting. It simply enforces one useful discipline: each test window comes after its training window.

The research process still needs to prevent repeated peeking at the same future windows.

Stress the parameters

If a 100-day threshold works, test 80, 90, 110, and 120. If a volatility filter uses 20 days, test nearby values.

You are looking for a region of reasonable performance, not the single best coordinate on a historical surface.

Stress the economics

Increase estimated slippage. Delay entries. Reduce fill quality. Remove the best trade. Start the backtest a year later. Change the rebalance day.

A strategy that survives only under the most favorable assumptions is not robust enough for live capital.

Reserve a final untouched period

The strongest simple safeguard is also the hardest psychologically: keep some data that you do not use while designing the strategy.

Do not inspect it after every change. Do not optimize against it indirectly. Use it late, when the research logic is already fixed.

If the result disappoints, that is valuable information.

Expect degradation

A live strategy does not need to match its historical Sharpe ratio to be valid. In fact, some degradation should be expected because historical research benefits from cleaner data, hindsight about implementation, and selection.

A backtest that advertises extraordinary precision deserves more scrutiny, not less.

What a robust backtest usually looks like

A believable strategy often looks less impressive than an overfit one.

Its parameter surface is broad rather than spiky. It has losing periods. Costs matter but do not erase the entire result. Performance is not dominated by one trade or one year. The economic explanation makes sense before you inspect the final equity curve.

Most importantly, the research process is designed so that failure remains possible.

That is the standard worth aiming for. The goal of a backtest is not to produce the prettiest historical chart. It is to make it difficult for a bad idea to fool you.

If you are building your own research system, our algorithmic trading backtester series covers the implementation side, while the Backtesting financial term provides a shorter conceptual reference.

Sources and further reading