Learn › Overfitting in backtesting

Overfitting in Backtesting: What Curve Fitting Is and How to Avoid It

A backtest is overfitted when a trading rule has been adjusted so closely to past prices that it fits their random moves as well as any real pattern. The rule can look very successful on the data used to build it and do much worse on new data. The same thing is also called curve fitting.

What is overfitting in a backtest?

Every price history mixes two things: patterns that may repeat, and random moves that will not. A rule fitted closely to one history learns both. On new data the random part is different, and the part of the result that came from it is gone.

A coin toss shows the effect, in simplified form. One person tossing a fair coin 10 times has a 5.5% chance of 8 or more heads, so among 100 people about 5.5 on average get there by luck alone. Asked to toss again, they average about 5 heads in 10. Keeping the best of many versions of a trading rule picks a winner the same way, and part of its backtest result can be luck of the same kind.

How does optimising a backtest lead to overfitting?

Optimising a backtest means trying several settings and keeping the one that did best. Each setting tried is another chance for luck to produce a good result. Two things increase the risk:

Every indicator added to a rule brings its own settings, so the number of possible versions grows quickly with each one.

How often do combinations of technical indicators overlap?

We measured how closely the daily readings of 30 popular indicators moved together on 483 S&P 500 stocks (Study 022). From the same results we counted every combination a trader could build from those 30 indicators, a count we added after the main results that uses them unchanged.

Three-indicator combinations of our 30 indicators (4,060)Overlapping: correlation 0.6 or more in either direction. Largely distinct: under 0.3 for every pair.0%25%50%75%100%share of the combinationsAt least one overlapping pair72%Every pair largely distinct6%
All 4,060 combinations of three of the 30 indicators; correlations from 483 current S&P 500 members, daily bars, each stock over its own years from 20 October 2006 to 30 September 2026.

72% of the three-indicator combinations held at least one pair with a correlation of 0.6 or more, in either direction, and 39% of the 435 pairs did. In those combinations an added indicator brings more settings to optimise without necessarily bringing a reading that behaves differently. Only 6.0% of the three-indicator combinations had a correlation under 0.3 for every pair.

This count describes how often three-indicator sets contain readings that are already related. It does not measure overfitting, which comes from repeated choices judged on the same data. It shows one way extra indicators can add settings and complexity without adding a distinct reading.

A low correlation does not prove that two indicators carry independent information, and correlation alone cannot say whether an indicator improves a particular rule. That needs a test of the rule itself.

How to avoid overfitting a backtest

The first three are the main defences; the others reduce the risk further.

Testing across different market conditions

A rule may work well in one kind of market and struggle in another. Checking its results in rising, falling and sideways markets, and in calmer and more volatile periods, shows whether the overall backtest rests on one environment. A rule that depends on one kind of market may be less robust than its total result suggests. Define the conditions before looking at the results, for example a rising market as the index above its 200-day average: labels chosen after seeing the results can be fitted too.

Common questions

What is overfitting in trading?

A trading rule adjusted until it fits the past prices it was tested on, including their random moves. It tends to do worse on new data than its backtest showed.

What is curve fitting?

Another name for overfitting: fitting a rule’s settings to one price history so closely that the fit includes noise.

How can I tell if a backtest is overfitted?

Common signs are a result that falls apart when a setting changes slightly, a result that holds on one period or stock and not on others, very few trades behind a strong result, and a rule chosen as the best of many versions with no test on data kept apart.

Is optimising a backtest bad?

Optimising chooses settings from data; the risk comes from trying many versions and judging the winner on the same data. Testing the chosen settings on data kept apart, or walk-forward testing, measures how much of the result carries over.

What is in-sample and out-of-sample testing?

In-sample data is the history used to build and tune a rule. Out-of-sample data played no part in choosing it, usually a later period kept apart from the start. A rule judged only in-sample is judged on the data it was fitted to.

Can a strategy be profitable in-sample and fail out-of-sample?

Yes. A strong in-sample result that weakens out-of-sample is a warning sign of overfitting, although changes in market conditions, execution and costs can also contribute.

How many backtests are too many?

There is no fixed number. The more versions are tried, the more likely the best of them looks good by chance, so a result is easier to judge when the number of versions behind it is counted and the chosen version is tested on data it never saw.

Does walk-forward testing prevent overfitting?

It reduces the risk and measures it, but does not remove it. Each training window uses only data from before its test window, and the test window plays no part in choosing the settings. If the design of the walk-forward test is itself changed many times after looking at its results, the out-of-sample record becomes part of the tuning.

Does adding more indicators cause overfitting?

Not by itself. Adding an indicator adds settings and combinations, which raises the risk when the rule is optimised again and again on the same data. In our count, 72% of three-indicator combinations of 30 popular indicators held a pair with a correlation of 0.6 or more, so the extra indicator often added settings to tune without a reading that behaved very differently.

How does GU Analyser help avoid overfitting?

GU Analyser lets you build trading rules visually and test them on past prices without writing code. You can set a percentage cost for buys and another for sells, compare results with buying and holding, and use event studies to see what followed each signal. These tools help you investigate a rule; avoiding overfitting still depends on how you design, test and check it.

Related: survivorship bias in backtesting · how to backtest a trading strategy without code.

Repeat the test on more than one stock

GU Analyser backtests a rule on one stock at a time, on daily bars, with costs and a buy-and-hold comparison, and its event studies show what followed a signal — built visually, no code. When a backtest or an event study uses two or more indicators, the indicator overlap check under the result gives the rank correlation of their readings (Spearman’s, the measure of Study 022), on the stock of that run, or averaged when the run covers several stocks. It shows how closely the readings moved together; whether the rule works is a question for the backtest itself.

Create a free account → Try the demo — no registration or start with the courses →
This is educational material, not advice. It describes methods and conventions used to study markets on historical data. Nothing here is a recommendation to buy or sell anything, and a historical test does not show what will happen next. GU Analyser is an analytical and educational tool — no money is ever traded here.