2026-12-04 · The Spera team
Walk-Forward Analysis: How to Tell If Your Backtest Is Overfit
Walk-forward analysis explained with worked examples. In-sample vs out-of-sample, holdouts, the deflated Sharpe ratio, and the signs a backtest is overfit.
TL;DR
- Backtest overfitting happens when a strategy's rules and parameters fit the noise in one stretch of history instead of a pattern that repeats. The more versions you try, the better the best one looks, whether or not there is anything real behind it.
- In-sample data is what you tuned on. Out-of-sample data is what you didn't. Only the second says anything about the future.
- Walk-forward analysis repeats the in-sample/out-of-sample split many times in a row: optimise on one window, test on the next unseen window, roll forward, and stitch the unseen pieces together.
- Count your trials. The deflated Sharpe ratio and the probability of backtest overfitting both correct a result for how many ideas were tried before it was kept.
- Warning signs: a parameter "cliff", too few trades, an out-of-sample collapse, and an equity curve that is smoother than the market it traded.
What is backtest overfitting?
A backtest replays your rules over historical prices. Every rule you add and every parameter you set is a choice, and every choice can be made to suit the particular wiggles of the window in front of you. Do that enough and the strategy stops describing the market and starts describing the sample. That is curve fitting, and the result is an overfit backtest: excellent on paper, ordinary or worse afterwards.
You rarely notice yourself doing it. Moving an EMA from 20 to 22 because the result improved looks reasonable. Repeat it fifty times across five parameters and you have run an optimiser by hand.
A simple example: the best of many coin flips
Here is a piece of hypothetical arithmetic. It is not a backtest of anything.
Imagine 100 strategy variants with no edge at all: their true Sharpe ratio is zero. You test each one on a year of daily data. Because a year is short, each measured annual Sharpe is roughly a draw from a bell curve centred on zero with a standard deviation of about 1.
The maximum of 100 such draws lands, on average, around 2.5. So if you try 100 variants and keep the winner, you should expect to "discover" a Sharpe near 2.5 even though every variant is worthless. With four years of data the spread halves, and the expected winner drops to around 1.25. Still impressive, still pure noise.
The lesson: the number of trials matters as much as the result, and short samples make it worse. A Sharpe of 2 from one idea and a Sharpe of 2 from the best of 500 grid points are very different claims.
In-sample vs out-of-sample: what's the difference?
In-sample data is every candle the strategy was built, tuned, or chosen on. Out-of-sample data is a stretch of the same market that played no part in those decisions.
An in-sample result can't separate skill from fit. An out-of-sample result can, because unseen data carries fresh noise: a real pattern tends to show up again, a fitted one tends not to.
The simplest version: a holdout
The holdout is one split. You cut the history at a point in time, build and tune on the earlier part, and score on the later part once, at the end.
Every edit, every setting you tried, every result you looked at.
Scored once, at the end. Never seen while tuning.
Three rules make a holdout honest:
- Split by time, not at random. Markets have memory, regimes and trends. A random sample of candles leaks information across the split.
- Look at it once. If you check the holdout, tweak, and check again, it has become in-sample. A holdout only works while it is unseen.
- Keep it big enough to score. A holdout with six trades can't tell you anything, whichever way it points.
A single holdout is one draw: the split might land on a stretch that happens to suit, or hurt, your strategy. Walk-forward analysis addresses that.
How does walk-forward analysis work?
Walk-forward analysis (often called walk-forward optimisation when parameters are re-fitted at each step) turns the single split into a sequence. Robert Pardo formalised it for trading systems in The Evaluation and Optimization of Trading Strategies, and the procedure is still the standard one.
Step by step
- Pick an in-sample length and an out-of-sample length. For example, 12 months to optimise on, 3 months to test on.
- Optimise on the first in-sample window. Choose the parameters by whatever rule you would use in real life, such as the best Sharpe across a grid.
- Freeze those parameters and run them on the next out-of-sample window. That window must come immediately after, and the optimiser must never have seen it.
- Roll forward by the out-of-sample length and repeat: re-optimise, then test on the next unseen window.
- Stitch the out-of-sample segments together. The joined curve is the walk-forward result. Every trade in it was made by parameters chosen without knowledge of that period.
A hypothetical layout: with 36 months of history, a 12-month in-sample window and a 3-month step, you get 8 out-of-sample windows covering the last 24 months. The first optimisation uses months 1 to 12 and trades months 13 to 15. The next uses months 4 to 15 and trades months 16 to 18, and so on.
What you read from the result:
- Walk-forward efficiency: out-of-sample performance divided by in-sample performance. A ratio near 1 means the optimised performance carried over. A ratio near 0 means it was mostly fit.
- Consistency across windows: how many out-of-sample windows were profitable, and how bad the worst one was. A stitched curve whose whole gain came from one window is a lucky window, not a strategy.
- Parameter stability: whether the optimiser keeps choosing similar values. If the "best" period jumps from 9 to 47 to 14, the optimiser is chasing noise.
Anchored vs rolling windows
| Anchored (expanding) | Rolling (sliding) | |
|---|---|---|
| In-sample window | Always starts at the first bar and grows | Fixed length, slides forward |
| Strength | Uses all history; parameters change slowly | Adapts to regime change; old data drops out |
| Weakness | Slow to adapt; early regimes keep their weight | Fewer bars per fit; parameters can whipsaw |
| Suits | Slow, structural edges | Edges you expect to drift |
How long should each window be?
Window length is a trade-off between two kinds of error:
- Longer in-sample windows give the optimiser more trades to fit, so parameters are estimated with less noise. But they react slowly when the market changes.
- Shorter out-of-sample windows give you more windows and a finer picture of consistency. But each one holds fewer trades, so each score is noisier.
Size windows by trade count, not calendar time, and fix the lengths before you see results. Trying several window schemes and keeping the best-looking one is overfitting one level up.
Purge and embargo: closing the leak at the boundary
If trades last several bars, a trade opened near the end of an in-sample window can close inside the out-of-sample window, and information leaks across the split. Marcos López de Prado's remedy has two parts:
- Purge: remove from training any observation whose outcome overlaps the test window.
- Embargo: leave a small gap of bars after a test window before training data resumes, so features that look back across the boundary don't carry test information.
A useful rule of thumb: make the gap at least as long as your longest typical holding period.
The multiple-testing problem: why the number of trials matters
Walk-forward analysis protects one strategy from its own optimiser. It does not protect you from the other 40 strategies you tried before this one. Each new idea is another draw, and the best draw is biased upwards, exactly as in the coin-flip example above.
Two papers by David Bailey and Marcos López de Prado give that intuition a number.
The deflated Sharpe ratio
The Deflated Sharpe Ratio (Bailey & López de Prado, Journal of Portfolio Management, 2014) asks: given how many trials were run, how varied they were, how long the track record is, and how skewed and fat-tailed the returns are, what is the probability that this Sharpe ratio reflects a true Sharpe above zero?
Conceptually it works in two moves. First, estimate the Sharpe ratio you would expect from the best of N trials if none had an edge. Then ask how confidently the observed Sharpe clears that bar, not the usual bar of zero. More trials raise the bar. Longer track records narrow the uncertainty. Negative skew and fat tails widen it.
You can try it on your own numbers with Spera's free Deflated Sharpe Ratio calculator.
The probability of backtest overfitting
The Probability of Backtest Overfitting (Bailey, Borwein, López de Prado & Zhu, published in the Journal of Computational Finance) measures overfitting directly from the set of trials you ran.
The method, combinatorially symmetric cross-validation, splits the history into blocks and forms every way of dividing them into equal in-sample and out-of-sample halves. For each division it picks the best configuration in-sample and checks where that configuration ranks out-of-sample. PBO is the share of divisions in which the in-sample winner falls below the median out-of-sample. A PBO near 0.5 or above means picking the in-sample winner is no better than picking at random.
The practical point of both papers: record every trial. You can't deflate a result if you've forgotten how many versions came before it.
How to tell if a backtest is overfit: warning signs
| Warning sign | What it looks like | Why it points to overfitting |
|---|---|---|
| Parameter cliff | Period 21 is great; 19 and 23 lose money | A real edge is usually a plateau. A single sharp peak was drawn, not discovered. |
| Too few trades | A high Sharpe from 15 trades | With so few trades, luck and skill produce the same numbers. |
| Out-of-sample collapse | Strong in-sample, flat or negative out-of-sample | The fit didn't transfer. This is the most direct evidence there is. |
| Concentrated returns | Most of the profit came from one month or one walk-forward window | The total is a lucky stretch, not a repeatable process. |
| Too-smooth equity | A curve that barely dips while the market swung hard | Often a sign of look-ahead bias, unrealistic fills or rules fitted around every loss. |
| Fragile to costs | The edge disappears with realistic fees and slippage | Many fitted strategies trade too often for their gross edge to survive costs. |
None of these proves overfitting on its own. Two or three together should stop you deploying.
How Spera checks for overfitting
Spera's deep backtest includes both splits described above, plus checks that are hard to run by hand. Full detail is in the out-of-sample and walk-forward docs.
The holdout
You choose 20%, 25% or 30%, and Spera holds back the final slice of the window by time, showing you the actual date it cuts at. After the deep run, the strategy is scored again on that slice alone, and the two risk-adjusted returns are compared as a retention ratio:
| Verdict | Retention |
|---|---|
| Holds up | 0.70× or more |
| Degraded | 0.30× to 0.70× |
| Fitted | below 0.30× |
The check declines to answer when the evidence is too thin: it needs at least 20 closed trades in the held-out stretch, a holdout of at least 10% of the window, and an in-sample Sharpe above 0.1. Quick backtests deliberately show no holdout number. Once a held-out figure is visible in your edit-and-test loop, you start tuning against it, and it stops being out-of-sample.
Walk-forward windows
Money made in a clear majority of periods, no period materially negative.
One period carried the whole result. Remove it and there is nothing left.
Spera's walk-forward check cuts the window into 4, 6 or 12 equal consecutive periods and scores each one on its own, with the same graph and the same settings. It does not re-optimise parameters between windows. It asks whether the edge was there in every period, or only in one. A period is scored only if it has at least 10 closed trades and 30 bars, and the check needs at least 3 scored periods. The verdict is Consistent or Concentrated. Concentrated means the whole-window result rests on a minority of periods, or one period was materially negative.
The Edge Report and Edge Rating
The holdout and walk-forward are two of eight checks in the Edge Report. Others compare your entries against random entries with the same trade count and holding period, run the rules on a shuffled version of the same market, and re-run the strategy at neighbouring parameter values to catch a parameter cliff.
The Edge Rating letter deals with the multiple-testing problem directly. It discounts the backtest's Sharpe for the market's own move, harsher costs, luck and every version you ran, so re-tuning can never raise it. When a run belongs to a research study, the report adds an "after the search" reading that accounts for every idea tried in the study, and a one-time test on a sealed window nobody tuned against.
The Try to break it lesson walks through a deep run with both checks. For the groundwork, see How to backtest a crypto trading strategy.
Don't tune until the checks turn green
Every change you make to pass a check fits the strategy a little more to the same history. Fixing the failing row by adjusting parameters is how a holdout turns into in-sample data.
Backtests describe the past and are made with hindsight. Nothing here is investment advice, and no test can say how a strategy will perform in future.
FAQ
What is the difference between walk-forward analysis and a single holdout?
A holdout tests the strategy once, on one unseen slice at the end of the data. Walk-forward analysis repeats the test over many consecutive unseen windows, so a single favourable or unfavourable slice can't decide the verdict on its own.
Is walk-forward optimisation the same as walk-forward analysis?
The terms are often used interchangeably. Strictly, walk-forward optimisation re-fits parameters on each in-sample window before testing on the next one. Some tools, Spera's walk-forward check included, keep the strategy fixed and score each period separately to test consistency over time.
How many trades do I need for an out-of-sample test?
There is no universal number, but a handful is never enough. Spera's holdout requires at least 20 closed trades in the held-out stretch, and each walk-forward period needs at least 10. Fewer than that, and noise can produce almost any result.
Can a strategy pass walk-forward analysis and still be overfit?
Yes. If you tried many strategies and kept the one with the best walk-forward result, the selection itself is a fit. That is what the deflated Sharpe ratio and the probability of backtest overfitting correct for. Paper trading on data that didn't exist when you finished building is the final test.
What does the deflated Sharpe ratio tell me that the Sharpe ratio doesn't?
The ordinary Sharpe ratio assumes you tested one idea. The deflated Sharpe ratio raises the bar to the Sharpe you would expect from the luckiest of all the trials you ran, and adjusts for track-record length and non-normal returns. Try it in the Deflated Sharpe Ratio calculator.
Ready to see how your own idea does on unseen data? Build it in the Strategy Builder and run a deep backtest with a holdout and walk-forward.