Matana Labs

Overfitting in backtesting

An overfit backtest has learned the noise of one stretch of history instead of a repeatable edge, so it looks good on the data it was tuned on and fails on new data. In our test on 200 synthetic markets with no edge at all, the best of 96 moving-average settings averaged +5.1% a year where it was tuned and −1.4% in the following year. You catch it by testing on untouched data, shifting the settings, raising costs and adjusting for how many variants you tried.

Tuning on pure noise: the best setting averaged +5.1% a year while it was chosen and −1.4% on the third year it had never seen.
Tuning on pure noise: the best setting averaged +5.1% a year while it was chosen and −1.4% on the third year it had never seen.

Signs a backtest is overfit

An experiment: tuning on pure noise

We generated 200 synthetic markets, each three years of daily prices from a random walk with no trend, so there is nothing to find. On each, we tried a simple rule (hold while the close is above its N-day average) with every N from 5 to 100, using the first two years, with 0.05% costs per side, and kept the best N. Then we ran that N once on the third year.

Nothing was wrong with the backtests. The winner was chosen because it fitted that particular noise best, and noise doesn’t repeat.

In tuning the winner looked profitable in 74% of the markets; on the next year it made money in 41%.
In tuning the winner looked profitable in 74% of the markets; on the next year it made money in 41%.

Out-of-sample tests and walk-forward

The simplest defence is to keep the last part of your data untouched while you build and tune, then test on it once. Walk-forward repeats the idea: tune on a window, test on the next, move both forward, and join the test pieces into one result. If the strategy only works where it was tuned, walk-forward shows it.

The untouched part only stays untouched if you look at it once. Tuning again after seeing it turns it into tuning data.

Parameter shifts: a plateau, not a peak

Test the neighbours of every setting. A real effect usually fades gently as you move away from the best value: a plateau. An overfit one is a lone peak, with much worse results one step either side. A map of results across two settings makes peaks easy to see.

Costs ×2, ×3 and execution delay

Many strategies that look good have an average trade only a little larger than their costs. Doubling and tripling commissions and slippage shows how much room there is. Delaying every order by a few seconds shows whether the strategy depends on fills it couldn’t really get. If the edge disappears, it was never large enough to trade.

Monte Carlo and shuffled history

One backtest is one order of trades and one path through history. Reshuffling the trades or resampling them shows the range of drawdowns and results the same strategy could have had; shuffling the order of market days tests whether the result depended on one particular sequence. Our Monte Carlo guide works through an example.

Correcting for the number of attempts

The best of K tries always looks better than a typical try, even when none has an edge, as the experiment above shows with K = 96. Statistical corrections, such as the deflated Sharpe ratio, lower the bar the winner must clear as K grows. At the very least, record how many variants you tested and be more sceptical the more you tried.

The 31 checks in one table

Matana Labs (our product) runs these checks on a strategy and combines them into a score out of 100 with a plain-words explanation. The names and questions below come straight from the app; some checks run automatically, some are optional, and the forward test and incubation are steps you take yourself.

#CheckGroupWhat it asks
1Untouched sliceCoreConclusions drawn on one part of the history are checked on the part that wasn't touched during optimization.
2Walk-forwardCoreWhether the idea survives regular re-optimization, not just one lucky tail.
3Parameter shiftCoreA peak instead of a plateau is overfitting. Good logic doesn't die from shifting a threshold by a tenth.
4Costs ×2 and ×3CoreAn edge that only lives at near-zero commission isn't an edge.
5Execution delayCoreThe order was created at second T and filled later — at the price and volume of that later second. If the idea dies from a few seconds' delay, it isn't fit for a live market.
6Share of the second's volumeCoreSize ceiling: how much the strategy can take from the market without imagining fills.
7Random entryCoreIf random entries with the same trade profile give nearly the same result, there's no signal.
8Benchmark: buy and holdCoreA gain against nothing doesn't count as a win.
9Ablation: without oneCoreWhat's redundant in the logic and what holds up the gain. This is diagnostics of the construction, not a verdict on the edge.
10Crashes and days from the tapeCoreNot a textbook “2008”, but what's actually in the file: this symbol's worst drops and special days from this period.
11Result concentrationCoreThree trades made the whole gain — there's no repeatability.
12Dead rulesCoreTuning a rule that never fires changes nothing. A dead rule is a hole in the design, not proof that there's no edge.
13Market regimesOptionalWhere the strategy lives: in a trend, in a range, on calm or choppy days.
14Neighboring timeframesOptionalDoes the idea hold on neighboring steps, or only on one lucky one.
15Other tapesOptionalSame logic on another symbol — is there anything in it beyond the quirks of one symbol.
16Noise on its own tapeOptionalAn idea that dies from small price noise rests on random second-level coincidences.
17Monte Carlo: three dialsOptionalOne curve is one realization. The spread shows how much of the result and drawdown were luck.
18Custom segment by datesOptionalFor “that week I remember”. Result only, no status.
19Opposite signOptionalIf the mirrored strategy is nearly as good, that's the symbol's movement, not the idea.
20Calendar effect on the tailOptional“Thursday is better” and “best hour” aren't proven on the full history: they need to show up on a slice where they weren't searched for.
21Two optimization mapsTuningBest cell on the left and red on the right is a normal outcome — you should see it first.
22Adjustment for the number of attemptsTuningThe best of K always looks good. The honest Sharpe is adjusted for K.
23Combinatorial windows with a gapTuningTime is serial: ordinary cross-validation peeks across the seams. Here the seams are closed off by a gap, and the test slices are any pair, not necessarily consecutive.
24Forward test with no moneyBy handThe strategy must trade forward through new seconds of the tape, with no money at stake.
25Incubation with small capitalBy handThe path from history to money. The app doesn't walk it for you and doesn't set a “done” checkmark.
26Crash inside the positionStressWhat happens if the market crashes a minute after entry — not on average, but at the worst possible moment.
27Volatility ×2 and ×0.5StressThe market can be twice as choppy or twice as quiet. A strategy optimized for one range breaks in the other.
28Shuffled historyStressOne history is one order of days. In a different order, the same days could give a completely different drawdown.
29Without the best and worst market daysStressIf the whole gain was made on the ten strongest days for the symbol, that's not a strategy — it's lucky presence.
30Worst three monthsStressAverage numbers don't hold you up — the worst stretches do. How much you can lose in a quarter, and how long you'll wait after.
31Losing streakStressA long losing streak breaks people before it breaks the strategy. What matters is whether it's longer than plain chance would give.

Updated 2026-11-19. Educational content, not financial advice.

Keep reading

See Matana Labs plans, from free

Questions

What is overfitting in trading?

Fitting a strategy so closely to past data that it captures random noise instead of a repeatable pattern. It looks good on the data it was built on and fails on new data.

How do I know if my backtest is overfit?

Test it on data you didn’t use to build it, shift each setting a little, double the costs and count how many variants you tried. If the result depends on one exact setting or disappears on new data, it is likely overfit.

How much out-of-sample data do I need?

Enough for a meaningful number of trades in the out-of-sample part, often 20–30% of the history. Walk-forward testing uses the data more efficiently by repeating the tune-and-test step many times.

Does optimisation always cause overfitting?

No, but every extra setting you tune and every variant you try raises the risk. Prefer few settings, wide plateaus of good results, and a correction for the number of attempts.

What is walk-forward analysis?

Repeatedly tuning a strategy on one window of history and testing it on the next, then moving forward. The joined test results show how the strategy would have done if you had re-tuned it on a schedule.