Learn › Glossary › Overfitting

Overfitting

Tuning a strategy until it fits the historical data's noise rather than a real market pattern. Symptoms: many parameters, spectacular backtest, sharp sensitivity to small parameter changes, and disappointing live results. Defenses: fewer knobs, out-of-sample testing, walk-forward validation, and suspicion of your own best results.

A strategy is overfit when its rules have been adjusted until they describe one stretch of history very well, including the random parts. Every price series is a mix of repeatable behaviour and chance. A rule with enough settings can be tuned to match both, and the backtest then shows a return that came partly from chance. Chance does not repeat in the next window, so the live result is usually worse than the tested one.

The effect is easy to produce by accident. A trader tries an RSI threshold of 30, then 25, then 20, keeps the best one, and reports it as the strategy. The test that picked the winner cannot also judge the winner, because the winner was chosen for having done well on that data. The more settings tried, the more the best result is likely to owe to luck.

The usual signs are many parameters, a very strong backtest, results that change sharply when a setting moves a little, and a gap between backtest and live trading. The usual defences are fewer settings, testing on data the rule was not tuned on, and a habit of doubting the best number. The related terms out-of-sample testing, walk-forward analysis and backtesting cover the methods in more detail.

The material here is the DeployQuant backtests. The window is 2021-01-04 to 2026-10-02, or 5.74 years, starting from $10,000, with 12 strategy templates run on 59 funds. The headline runs charge no fees or slippage. All figures are hypothetical, and none of them is a forecast. The numbers below show where a tuned result can mislead and where a result gives some reason for trust.

Why the number of settings matters

Each setting in a rule is a place where the tester can choose. The 12 templates in the study are small on purpose. The 200-day regime filter has one setting, the length of the average. The golden cross has two, the 50-day and the 200-day lengths. The RSI(2) snapback has an entry level of 10 and an exit level of 70. The weekly 7% target has a target of 7% and a Thursday exit time. The 3-month momentum switch has a 63-day lookback, an entry of 5% and an exit of 0%.

A short list of settings limits how much a tester can fit. With two settings and a dozen values each, there are a few hundred combinations to search. With ten settings the number of combinations is far larger than the number of independent events in a 5.74 year daily series, and some combination will fit the past closely by chance. The templates were not tuned fund by fund. They apply the same fixed rule to every fund, which is the opposite of fitting each fund separately.

That design shows in the medians. For the RSI(2) snapback the median CAGR across the 59 funds was 4.74%. For the weekly 7% target it was 6.61%, for the monthly cycle 5.46%, for the RSI mean reversion rule 2.98% and for EMA 12/26 trend 2.76%. The momentum breakout and 3-month momentum rules both had a median of 0%. A fixed rule applied everywhere gives modest numbers in the middle of the table and a few large ones at the edges. A rule tuned to one fund would show only its best number.

Picking the best result out of many

Overfitting does not require a long parameter list. Choosing the best of many runs does the same thing. The study has 12 strategies and 59 funds, and each pair has its own result. A reader who scans all the pages for the highest CAGR will find some very large numbers, and the chance that those numbers repeat is lower than the chance that a typical result does.

The pages give a way to see the difference. The median of a strategy across all 59 funds describes what the rule did on an ordinary fund. The best fund is a selected result. For the weekly 7% target the median was 6.61%. The result on a single leveraged fund such as TQQQ, where swings are large, is a selected result, and taking it as the evidence for the rule would be choosing the tail.

The count of funds on which the rule beat buy-and-hold is a second guide. The weekly 7% target and the RSI(2) snapback each beat buy-and-hold on 34 of the 59 funds. The 200-day regime filter did on 26, the golden cross on 27 and RSI mean reversion on 25. EMA 12/26 trend and the dip buyer did on 22, SMA 10/50 trend and momentum breakout on 21, trend plus trailing stop and 3-month momentum on 20, and the monthly cycle on 14. Those are the counts when no fund was chosen in advance. A rule that beats buy-and-hold on 34 of 59 funds has done so on a little more than half, which is far less impressive than the best single page suggests.

In practice a trader who tests 20 ideas and publishes the best has run 20 searches. A fair summary of the work reports all 20, or reports the best one after a second test on data the search never saw.

How little data a backtest holds

The window is 1,444 sessions in one stretch of 5.74 years, and it contains a single large equity decline. SPY fell 24.51% from 2022-01-03 to 2022-10-12 and had not recovered until 2023-12-13. QQQ fell 35% from 2021-11-19 to 2022-11-03. Every strategy page in the study had one bear market to deal with, and the result of a rule for the whole window is strongly shaped by how it handled that one episode.

That is a small sample. A rule such as the golden cross has a median of 3 round trips per fund across the 59 funds. The dip buyer has a median of 2, and trend plus trailing stop has 4. A result that rests on 2 or 3 trades says almost nothing, because one trade can account for the whole difference between a good and a bad number. The rules with many trades give more evidence: the RSI(2) snapback has a median of 166 round trips, the weekly 7% target has 106 and the monthly cycle has 69. More trades give a better estimate of the average trade, though they do not fix the problem of a single window with a single bear market.

Sample size also affects signals. On SPY, RSI(14) fell below 30 on 18 sessions in the window, and the median 20-day forward return after those was 2.86% against 1.73% for all sessions. On QQQ it fell below 30 on 15 sessions and the median 20-day forward return was 1.42% against 1.74%. The same signal looked helpful on one fund and slightly unhelpful on the other, and each rests on fewer than 20 events. A tuned threshold built from either one would be fitted to a handful of days.

A rule fitted to one fund often fails on another

A real pattern tends to show up on more than one asset. A fitted one often does not. The oversold signal makes the point. After RSI(14) fell below 30, the median 20-day forward return was 2.86% on SPY, against a baseline of 1.73%. On QQQ it was 1.42% against a baseline of 1.74%. On IWM it was 0.22% against 0.82%, over 33 sessions. On TLT it was -1.63% against -0.6%, over 61 sessions. On TQQQ it was 6.9% against 3.62%, and on UVXY it was -5.82% against -11.36%.

The pattern in this table is mixed. Oversold readings were followed by better-than-baseline returns on SPY, TQQQ and UVXY, and by worse-than-baseline returns on QQQ, IWM and TLT. A trader who tuned an RSI threshold on SPY and saw an edge would find the edge missing on three of the six funds above. The rule was fitted to something that was real in one place and absent in others.

The buy-and-hold numbers show how different these funds were. Over the window SPY returned 14.56% a year with buy-and-hold, QQQ 16.7%, IWM 7.5%, TQQQ 25.35%, TLT -8.23% and UVXY -48.74%. A rule that has been shaped to fit a rising fund will do badly on a falling one, and TLT and UVXY are the extremes in the study. TLT closed above its 200-day average on only 35.18% of sessions and crossed it 95 times, while SPY closed above on 77.99% and crossed 30 times. A trend rule tuned on SPY would be walking into the whipsaws of TLT.

The study applies one rule to all 59 funds and publishes every result, including the poor ones. That protects against the most common form of fitting, but it does not remove the risk, because the window and the rule designs are still the same for every fund.

Sensitivity: how a result changes when a setting moves

One test for overfitting is to change a setting by a small amount and see whether the result holds. A real edge usually survives a modest change, and a fitted one often does not. Each strategy-and-fund page in the study carries a table of parameter variants for this purpose, along with results charged 5 and 10 basis points of slippage per fill.

The tables show the test being applied. On pages for rules with a smooth response, the variants cluster near the published result. On other pages they spread widely, and a spread is a sign that the published setting is one point on an uneven surface. The whole table matters, with the published row as one entry among several. If the published setting is the best of the set by a wide margin, it was probably chosen for that reason. If it sits in the middle, the result is more likely to reflect the idea than the setting.

A useful habit is to check that the neighbours of a setting behave like it. A 5-day entry that works while 4 and 6 fail is a sign of a result that rests on a few days. A setting that works while its neighbours do about as well is evidence for a broader effect. The costs tables serve the same purpose from another side. A result that disappears with 5 basis points of slippage was too thin to rely on.

Sensitivity testing is useful, but it has a limit. The variants are tried on the same window as the headline run, so they test fragility and do not test the future. A rule can be stable across its neighbours and still fail in a different period.

Hidden fitting: costs, timing and survivorship

Fitting does not always appear as a parameter. A backtest that ignores costs favours rules that trade often, because those rules make small gains that costs would remove. The RSI(2) snapback has a median of 166 round trips per fund, so its headline figures are the most exposed to this. The study runs every strategy at 5 and 10 basis points of slippage for that reason, and the difference between the headline run and the cost runs is part of reading any page.

Timing is a second source. The study evaluates daily-decision rules, fills orders on minute bars and uses prices adjusted for splits and dividends. A rule that peeks at the day's close to decide an order at the open would look better than any real rule could be. The backtests here decide using prior data and fill at the open, but a reader building their own rules should check for the same problem. A result that is far better than neighbouring rules deserves a check for look-ahead before it deserves trust.

The choice of funds is a third source. The 59 funds are those in the study, and a fund that closed or merged would not appear in a list built after the fact. A rule that did well on the funds that exist today has been tested on the winners of the sample. The study does not claim to correct for this, and no result here should be read as a statement about funds that were left out.

Defences that work in practice

The first defence is to start with an idea that has a reason, then test it with the fewest settings that express it. The study's templates each follow that pattern. The 200-day filter says to own an asset only while it is above its long average. The weekly target says to take a 7% gain and avoid carrying a loser into the weekend. Each template can be explained in a sentence, and the reasoning comes before the numbers.

The second defence is to hold data back. Out-of-sample testing means designing the rule on one part of history and judging it on another part that was never used for tuning. Walk-forward analysis repeats that process through time. Paper trading on live data is a stricter version, because the data does not exist yet when the rule is written. DeployQuant offers paper trading on the live market data feed, and it needs no broker.

The third defence is to look at the trades. DeployQuant logs each decision with the prices and indicator values the strategy saw, so a reader can check whether the profit came from many ordinary trades or from one or two. A result that rests on one trade is a sign of luck. The RSI(2) snapback has many trades per fund, and the dip buyer has a median of 2, so the two call for different levels of caution.

The fourth defence is to look at the median and not the maximum, and at the count of funds that beat buy-and-hold. These describe what a rule did without selection. The fifth is to lower expectations deliberately. If a backtest shows a figure, a live result somewhat below it is the usual case, and a plan should not depend on the backtest number.

The answer on avoiding overfitting and the guide to building a first trading algorithm go through these steps as a checklist, and the page on the biggest risks of automated trading places overfitting next to the other ways an automated strategy can fail.

What this page does and does not show

The numbers on this page come from one window of 5.74 years, one set of 12 rules and 59 funds, daily decisions and minute-bar fills. They describe what happened in that sample. They do not measure how much of any result is luck, and they do not predict later returns. The comparison of oversold signals across six funds is a small number of events per fund, and the medians of the strategies are medians over one window.

The lesson that carries over is the method: count the settings, look at the median and not the best case, check neighbouring settings, test on data the rule never saw, and read the trade list. None of these removes the risk of overfitting. They make it easier to see.

Frequently asked questions

What is overfitting in trading?

Overfitting is tuning a strategy until it matches the noise in historical data as well as the real pattern. The backtest then looks better than the strategy will perform later. The usual signs are many parameters, a very strong backtest, sharp sensitivity to small changes in a setting, and poor live results.

How can I tell if a backtest is overfit?

Change each setting by a small amount and see whether the result holds, count the settings, and check how many trades the result rests on. A rule with a median of 2 or 3 round trips, like the dip buyer or the golden cross, rests on very few events. A result that disappears at 5 basis points of slippage was too thin to trust.

Does a long backtest remove overfitting?

A longer window helps, because it holds more market conditions. This study covers 5.74 years with one large decline, 2022, so every rule had one bear market to handle. More data reduces the risk without removing it, because tuning on any window can still fit that window.

Why look at medians instead of the best result?

The best result across 12 strategies and 59 funds is a selected one. The median describes an ordinary fund. For the weekly 7% target the median CAGR was 6.61% and the rule beat buy-and-hold on 34 of 59 funds, which is a fairer summary than its result on one leveraged fund.

Is a rule that works on one fund evidence of a real edge?

It is weak evidence. RSI(14) oversold readings were followed by above-baseline 20-day returns on SPY, 2.86% against 1.73%, but below-baseline returns on QQQ, 1.42% against 1.74%. A pattern that shows up on several unrelated funds is more convincing than one that shows up on a single fund.

How does paper trading help?

Paper trading tests a rule on data that did not exist when the rule was written, which is the strictest out-of-sample test. DeployQuant paper trades on its live market data feed and needs no broker. A few weeks is a short sample, so it complements the backtest and does not replace it.

Run a strategy that uses this yourself, free →

Build it from blocks (or type it in English), backtest it on 5.7 years of minute data in seconds, tweak any parameter, then paper trade it on live data. No card, no broker needed to start.

Related terms

Out-of-Sample TestingEvaluating a strategy on data it was not developed or tuned on — the l…Walk-Forward AnalysisRepeatedly optimizing a strategy on one window of history and testing …BacktestingSimulating a strategy's rules against historical market data to estima…

Backtests are hypothetical, computed by DeployQuant's engine on minute-resolution consolidated US market data (2021-01-04 to 2026-10-02, $10,000 starting capital, no margin, no fees or slippage in the headline run; buy-and-hold puts 98% of the account in at the first open, as the templates do) and do not guarantee future results. Nothing on this page is investment advice. Live trading involves risk of loss.