What is overfitting in a backtest?

A backtest replays a set of rules against historical prices. Any historical period contains two things mixed together: patterns that may recur, and random noise that will not. Overfitting is what happens when a strategy is shaped to match both, including the noise. The result is a strategy that fits the past almost perfectly and has little to say about anything else.

A useful comparison is a student who memorizes last year's exam answers instead of learning the subject. The memorized answers score perfectly on last year's exam and poorly on a new one. An overfit strategy does the same with price history.

Why does overfitting happen?

Three causes show up again and again.

How many variations have you tried?

This is the most important question to ask about any backtest result, and it is the one most often skipped.

Suppose you flip a coin ten times and get eight heads. That is mildly surprising. Now suppose you flip 1,000 coins ten times each and report only the coin that landed eight or more heads. That result is not surprising at all, because with enough tries something will look unusual by chance alone. This is the multiple-testing problem.

Strategy search works the same way. Trying 50 combinations of settings and reporting the top-ranked one is not the same as testing one idea. A rough rule of thumb: the more variations you try, the higher the bar a result must clear before you take it seriously. A result that survives after you honestly count every attempt is far more meaningful than one that does not.

A hypothetical example

The numbers below are made up to illustrate the pattern. They are not real results.

Imagine a simple moving-average crossover rule. You test 40 combinations of fast and slow lengths on 2016 to 2020 data, then pick the combination with the highest annualized return. You then run that same combination on 2021 to 2024 data that was set aside and not used for tuning.

Hypothetical testAnnualized return
Average of all 40 combinations, tuning period3%
Top-ranked combination, tuning period14%
Same combination, unseen period1%

Hypothetical example for illustration only.

The top-ranked combination looks impressive in the tuning period, but part of that is selection: out of 40 tries, one was bound to look good. On unseen data, the result falls back near the ordinary level. The gap between 14% and 1% is the cost of overfitting, and you only see it if you kept data in reserve.

What are the warning signs?

How do you reduce it?

Where Thulo fits

Thulo is an analytical platform that lets you describe a strategy in plain English and backtest it against historical data. The habits above apply to any backtesting tool: keep the idea simple, hold data back, and keep count of how many versions you try. Thulo does not provide investment advice, and the decisions about what to test and what to conclude remain yours.

Keep reading