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.
Signs a backtest is overfit
- The result depends on one exact setting: 20 works, 19 and 21 don’t.
- Many rules and filters, each added to remove a few losing trades.
- Few trades, or most of the profit from a handful of them.
- A smooth equity curve on the tuning period and a flat or falling one after it.
- You tried many ideas and are showing the best one.
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.
- The best setting looked profitable in tuning in 74% of the markets, averaging +5.1% a year.
- On the untouched third year it averaged −1.4%, and made money in only 41% of the markets.
Nothing was wrong with the backtests. The winner was chosen because it fitted that particular noise best, and noise doesn’t repeat.
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.
| # | Check | Group | What it asks |
|---|---|---|---|
| 1 | Untouched slice | Core | Conclusions drawn on one part of the history are checked on the part that wasn't touched during optimization. |
| 2 | Walk-forward | Core | Whether the idea survives regular re-optimization, not just one lucky tail. |
| 3 | Parameter shift | Core | A peak instead of a plateau is overfitting. Good logic doesn't die from shifting a threshold by a tenth. |
| 4 | Costs ×2 and ×3 | Core | An edge that only lives at near-zero commission isn't an edge. |
| 5 | Execution delay | Core | The 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. |
| 6 | Share of the second's volume | Core | Size ceiling: how much the strategy can take from the market without imagining fills. |
| 7 | Random entry | Core | If random entries with the same trade profile give nearly the same result, there's no signal. |
| 8 | Benchmark: buy and hold | Core | A gain against nothing doesn't count as a win. |
| 9 | Ablation: without one | Core | What's redundant in the logic and what holds up the gain. This is diagnostics of the construction, not a verdict on the edge. |
| 10 | Crashes and days from the tape | Core | Not a textbook “2008”, but what's actually in the file: this symbol's worst drops and special days from this period. |
| 11 | Result concentration | Core | Three trades made the whole gain — there's no repeatability. |
| 12 | Dead rules | Core | Tuning a rule that never fires changes nothing. A dead rule is a hole in the design, not proof that there's no edge. |
| 13 | Market regimes | Optional | Where the strategy lives: in a trend, in a range, on calm or choppy days. |
| 14 | Neighboring timeframes | Optional | Does the idea hold on neighboring steps, or only on one lucky one. |
| 15 | Other tapes | Optional | Same logic on another symbol — is there anything in it beyond the quirks of one symbol. |
| 16 | Noise on its own tape | Optional | An idea that dies from small price noise rests on random second-level coincidences. |
| 17 | Monte Carlo: three dials | Optional | One curve is one realization. The spread shows how much of the result and drawdown were luck. |
| 18 | Custom segment by dates | Optional | For “that week I remember”. Result only, no status. |
| 19 | Opposite sign | Optional | If the mirrored strategy is nearly as good, that's the symbol's movement, not the idea. |
| 20 | Calendar effect on the tail | Optional | “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. |
| 21 | Two optimization maps | Tuning | Best cell on the left and red on the right is a normal outcome — you should see it first. |
| 22 | Adjustment for the number of attempts | Tuning | The best of K always looks good. The honest Sharpe is adjusted for K. |
| 23 | Combinatorial windows with a gap | Tuning | Time 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. |
| 24 | Forward test with no money | By hand | The strategy must trade forward through new seconds of the tape, with no money at stake. |
| 25 | Incubation with small capital | By hand | The path from history to money. The app doesn't walk it for you and doesn't set a “done” checkmark. |
| 26 | Crash inside the position | Stress | What happens if the market crashes a minute after entry — not on average, but at the worst possible moment. |
| 27 | Volatility ×2 and ×0.5 | Stress | The market can be twice as choppy or twice as quiet. A strategy optimized for one range breaks in the other. |
| 28 | Shuffled history | Stress | One history is one order of days. In a different order, the same days could give a completely different drawdown. |
| 29 | Without the best and worst market days | Stress | If the whole gain was made on the ten strongest days for the symbol, that's not a strategy — it's lucky presence. |
| 30 | Worst three months | Stress | Average 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. |
| 31 | Losing streak | Stress | A long losing streak breaks people before it breaks the strategy. What matters is whether it's longer than plain chance would give. |
Keep reading
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.