Walk-forward analysis: the one backtest number you could have traded
Walk-forward analysis tunes a strategy on one window of data, trades the frozen setting on the next window, and repeats across the history. The joined out-of-sample result is the only backtest number you could actually have traded; the best setting over the whole history is a hindsight number you could not.
By Soren Huang · Published · updated · Editorial policy
Contents
- What is walk-forward analysis?
- What is walk-forward optimization?
- What does walk-forward analysis catch that one in-sample vs out-of-sample split does not?
- How long should in-sample and out-of-sample windows be?
- Rolling or anchored windows?
- How many walk-forward windows do you need?
- What is walk-forward efficiency and what is a good number?
- How do you run the same test on a grid of window settings?
- Can walk-forward analysis still be overfitted?
- Frequently asked questions
- References
What is walk-forward analysis?
Walk-forward analysis is a backtest method that tunes a strategy on one window of past data, trades the chosen setting unchanged on the next window, then moves forward and repeats. The joined out-of-sample result is the only backtest number you could have traded. The best setting over the whole history is a hindsight number you could not.
Judge the first number and ignore the second. Everything else in this article explains how to produce the first number so that it means something.
Think of a weather forecaster. To judge her, you do not ask how well she can explain yesterday's weather after it happened. You look at the forecasts she wrote the evening before, for days she had not seen yet. Walk-forward analysis applies that test to a trading strategy. Every parameter is chosen before the data it is then traded on, so the result is a record of forecasts, not a record of explanations.
Two terms carry the whole method. The in-sample window is the stretch of data the optimizer sees when it picks the parameters. The out-of-sample window is the stretch that follows, where the picked parameters are traded without any change. Walk-forward analysis repeats one cycle across the history:
- Optimize the parameters on the in-sample window, using the objective you fixed in advance.
- Freeze the chosen parameters and trade them on the out-of-sample window that follows, touching nothing.
- Move forward by the length of the out-of-sample window and repeat from step 1.
At the end you join the out-of-sample pieces into one equity curve. Each trade on that curve was taken with a setting that existed before the trade's data did. Beside it, you can also run the single setting that looks best over the whole history. That second curve is not a forecast record. You picked it after seeing every bar, so no trader in 2021 could have known it was the one to use. It is useful as a ceiling for comparison and for nothing else.
What is walk-forward optimization?
Walk-forward optimization is the re-tuning step inside each window, and four choices fixed before the first run decide whether that step means anything. The two terms are often used as if they were the same. Strictly, walk-forward optimization names the repeated optimize-and-freeze step, and walk-forward analysis names the whole test, including how you judge the joined out-of-sample result. Pardo (2008) built the method around this distinction: the optimization is the thing being tested, and the out-of-sample windows are the test.
Fix these four choices before you see a single out-of-sample number. Changing any of them after a bad window turns the test back into fitting by hand.
- The objective. Decide what the optimizer maximizes: net result after costs, or net result relative to drawdown, or another single number. Ranking on gross profit favours settings that trade too often, because commission and slippage remove the smallest edges first. The measured run later in this article uses net profit divided by month-end drawdown.
- The parameter ranges. Write down the values the optimizer may try, once. Widening the range because one window looked weak is a decision made with hindsight, and it leaks into every window after it.
- The selection rule. Decide how the winner inside each window is chosen. Taking the single best value tends to pick noise. Many traders prefer a value from the middle of a broad region where the neighbouring settings also do well, because a setting that only works at one exact value rarely works on the next window.
- The re-optimization interval. The out-of-sample length is also how often you would re-tune the live strategy. Pick a schedule you would really follow, for example every quarter or every year, not one that merely makes the backtest look smooth.
The separate article on walk forward optimization works through each of these four choices with examples and without the mathematics. Here the point is simpler: the optimization step is only as honest as the rules you wrote down before running it.
What does walk-forward analysis catch that one in-sample vs out-of-sample split does not?
One split gives a single out-of-sample verdict that can be lucky or unlucky; several windows show whether the re-tuning process keeps working across different years, and whether the picked parameters stay stable. A single in-sample vs out-of-sample split is a fair test of one setting on one stretch of data. It is the right first step, and it is not enough on its own, for two reasons.
First, one verdict has no context. If the out-of-sample year was a strong trend year, almost any trend rule looks good on it. If it was a choppy year, a sound rule can lose. With one split you cannot tell which case you are looking at. With five windows you can count: how many out-of-sample years were above zero, how large the worst one was, and whether the good years cluster in one market condition. The article on walk-forward out-of-sample P&L goes deeper into why the sign of one out-of-sample result says so little by itself.
Second, one split produces one set of parameters, so you learn nothing about parameter stability. Parameter stability is the degree to which the optimizer picks similar values from one window to the next. In the measured NQ run below, the five windows picked 20/100, 20/100, 40/50, 40/50 and 40/100 for the breakout length and the exit average. Each parameter moves only between two neighbouring values and never jumps from one end of its range to the other. That is the kind of history you want to see. If the picks had been 10/20, 40/100, 10/50, 40/20 and 20/100, the strategy would have no stable region in that parameter space, and the joined out-of-sample result would be hard to trust even if it were positive.
Reading these two things, consistency and stability, needs the trades sorted by which window they belong to. Inside MultiAlphas (Valynox), the walk-forward windows run as part of strategy validation with thresholds you set, and the trades report lets you switch between all trades, in-sample trades only and out-of-sample trades only, so the comparison in this section is one click rather than a spreadsheet exercise.

How long should in-sample and out-of-sample windows be?
Size the in-sample window by the number of trades it holds, roughly 30 to 50 at least, not by the calendar, and keep out-of-sample at about one third to one fifth of in-sample so that the re-tuning schedule is one you would follow when trading. A calendar length such as "three years" means nothing on its own. Three years of a daily-bar strategy that trades twice a month is a different test from three years of a 60-minute strategy that trades twice a week.
The reason is what an optimizer does with too few trades. Give it a window with 20 trades and nine parameter combinations, and the best combination is usually the one that happened to dodge two or three losing trades. That is not a pattern; it is an accident of the sample, and it will not repeat on the next window. Give the same optimizer a few hundred trades and the accidents average out, so the winning combination has to win for a reason that covers many trades.
Hypothetical example
Two strategies are tested over the same 36 months. The first trades on daily bars and takes about 20 trades in that time. The second trades on 60-minute bars and takes a few hundred. With a 36-month in-sample window, the first strategy gives the optimizer far fewer than the 30 to 50 trades it needs, so its picks will mostly reflect noise. The second strategy clears the minimum several times over. To test the first strategy fairly, its in-sample window would have to stretch to perhaps eight or ten years, which also means fewer windows can fit into the history you have.
Work the sizing in this order:
- Count trades per year from a plain backtest with a middle-of-the-range setting. This is the one number the whole plan rests on.
- Set the in-sample length so that it holds at least 30 to 50 trades. Strategies with more parameters need more, because each extra parameter gives the optimizer another way to fit accidents.
- Set the out-of-sample length at about one third to one fifth of in-sample. Ratios between 3:1 and 5:1 are common. The measured run below uses 36 months to 12, a 3:1 ratio.
- Check the schedule. The out-of-sample length is how often you would re-tune live. If you would never actually re-optimize every month, do not test with one-month out-of-sample windows.
- Check the coverage. The full history should include trending, ranging, calm and volatile stretches, so that the out-of-sample windows are not all drawn from one kind of market.
A shorter out-of-sample window gives more re-optimizations and a closer imitation of periodic re-tuning, but each window then holds fewer trades to judge. A longer one gives a firmer verdict per window and fewer windows. There is no setting that is right for every strategy, which is why the matrix in a later section exists.
Rolling or anchored windows?
A rolling window drops the oldest data and adapts faster, an anchored window keeps growing and uses more data; the choice should match how you would re-tune live, and running both tells you whether the strategy depends on it. A rolling window is an in-sample window of fixed length that slides forward with each step. An anchored window is an in-sample window that always starts at the first bar of the history and grows longer with each step.
| Rolling window | Anchored window | |
|---|---|---|
| In-sample start | Moves forward each step | Always the first bar |
| In-sample length | Fixed, for example 36 months | Grows by one out-of-sample length each step |
| Trades per window | Roughly constant | Increases over the history |
| Reaction to a changed market | Faster, old data is dropped | Slower, old data keeps its vote |
| Parameter picks | Tend to move more between windows | Tend to settle as the window grows |
| Fits a trader who | Re-tunes on recent years only | Re-tunes on everything available |
Choose the one you would really use. If your live habit is to re-optimize on the last three years every autumn, test with a rolling 36-month window, because that is the process the test is supposed to judge. If you would always use all the data you own, test anchored. The test loses its meaning when it imitates a re-tuning habit you do not have.
Then run the other one as well. If rolling and anchored give similar out-of-sample results and similar parameter picks, the strategy is not sensitive to this choice, and that is one more sign of a stable edge. If they disagree sharply, the strategy's result depends on which years the optimizer was allowed to see, and you have learned something important before risking money on it. The measured run in this article is rolling only, so it shows one half of that comparison and not the other.
How many walk-forward windows do you need?
Enough out-of-sample windows to count wins and losses and spot a single lucky year, which in practice means a long enough history for at least four or five windows at the chosen out-of-sample length. The joined out-of-sample curve is only as convincing as the number of independent verdicts inside it.
Think of a new mechanic. One repaired car tells you nothing: it might have been an easy job. Two cars, one fixed and one not, leave you unable to decide. Five cars with four repaired let you form an opinion and ask what went wrong with the fifth. Out-of-sample windows work the same way.
- One window is an in-sample vs out-of-sample split. It gives a single result and no way to tell luck from skill.
- Two windows that disagree, one above zero and one below, leave the question open, and two that agree are still too few to rule out two lucky years in a row.
- Four or five windows let you count. You can say "four of five above zero", name the weak year, and look at what the market did in it. You can also read the parameter picks as a sequence.
The cost is history. With 36 months in-sample and 12 months out-of-sample, five rolling windows need 36 plus five times 12 months, which is 96 months, or eight years of data. The measured run below used 98 months of NQ 60-minute data, just enough for five windows at those lengths. A tenth window would need five more years. This is one reason to prefer out-of-sample windows that are shorter than in-sample: each extra window costs only one out-of-sample length of history, not a full in-sample block.
If your history is too short for four windows at the lengths you want, shorten the out-of-sample window before you shorten the in-sample one, because the in-sample trade count is the limit that protects the optimizer from noise. If even that does not fit, the honest result is that the data is too short for a walk-forward verdict yet, and a single split is what you can report.
What is walk-forward efficiency and what is a good number?
Walk-forward efficiency compares the out-of-sample performance rate with the in-sample rate; the measured NQ 60-minute run below, five rolling windows, joined out-of-sample $208,027 against a hindsight single setting of $349,998, efficiency 94%, shows what the number means and what a rising market does to it. Walk-forward efficiency is the term Pardo (2008) uses for this ratio, and it answers one question: of the performance the optimizer saw while tuning, how much survived on data it had not seen?
The ratio has to compare rates, not totals, because the windows have different lengths. The one formula in this article is:
Walk-forward efficiency = (out-of-sample profit ÷ out-of-sample months) ÷ (in-sample profit ÷ in-sample months)
Here "out-of-sample profit" is the joined net result of all out-of-sample windows, "out-of-sample months" is their total length, and the two in-sample figures are the same sums across every in-sample window. Each side becomes a profit per month, and the efficiency is how large the out-of-sample rate is as a share of the in-sample rate. A result of 100% would mean the frozen settings earned at the same monthly rate on unseen data as the optimizer saw while tuning. A small fraction means most of what the optimizer found was noise that did not carry forward. If you prefer a rate that also accounts for how rough the ride was, the Sharpe ratio calculator gives the Sharpe ratio of a return series, and you can compare out-of-sample with in-sample on that measure in the same way.
Here is a real run with the settings written out in full:
Source: MultiAlphas hosted backtest (ap_backtest connector), run 2026-10-31
| Out-of-sample year from | Picked in-sample (N / M) | In-sample profit, 36 months | Out-of-sample profit, 12 months |
|---|---|---|---|
| 2021-09 | 20 / 100 | $103,939 | $28,513 |
| 2022-09 | 20 / 100 | $151,289 | $47,296 |
| 2023-09 | 40 / 50 | $126,744 | $77,343 |
| 2024-09 | 40 / 50 | $161,579 | −$623 |
| 2025-09 | 40 / 100 | $122,960 | $55,499 |
Joined out-of-sample: $208,027 over 60 months, 4 of 5 years above zero, month-end drawdown $44,703. The single setting that looks best over all 98 months, chosen with hindsight (10 / 100), made $349,998 over the same 60 out-of-sample months. Walk-forward efficiency on these windows: 94%. NQ rose over this period, and that rise sits inside every number here.

Read the table from left to right, one window at a time. In September 2021 the optimizer saw the 36 months behind it, picked N 20 and M 100, and that setting then made $28,513 on the twelve months it had never seen. In September 2022 the window moved forward a year, the pick stayed at 20/100, and the frozen setting made $47,296. In 2023 the pick moved to 40/50 and made $77,343; in 2024 the same pick made −$623, a year that ended almost flat; in 2025 the pick moved to 40/100 and made $55,499. Added up, the five out-of-sample years give the joined total in the box above, with the month-end drawdown beside it. Every dollar of that total was earned by a setting chosen before its year began. That is the number a trader following this exact re-tuning schedule, with these costs, could have had.
Now the second number. The single setting that looks best over all 98 months is 10/100, and over the same 60 months it made more than the joined total. Notice that 10/100 was never picked by any window. None of the five 36-month in-sample stretches pointed at it. The only way to arrive at 10/100 was to look at the full history after it had happened. It is a ceiling, and it tells you how much the optimizer "gave up" by working forward in time, but it is not a result anyone could have traded. Judging a strategy by that number is the mistake walk-forward analysis exists to remove.
What is a good efficiency? The 94% here means the out-of-sample monthly rate was almost as high as the in-sample monthly rate, which is a strong reading for this one run. Many traders treat out-of-sample keeping half or more of the in-sample rate as acceptable and a small fraction as a sign the optimizer was fitting noise. Treat these as working thresholds, not laws. Two things about this run keep the 94% in proportion. First, it is long only on a market that rose over the whole period, so part of every window's profit, in-sample and out-of-sample alike, is the market itself rather than the breakout rule. A rising market lifts both sides of the ratio and can leave the efficiency high even when the rule adds little. Second, this is one strategy on one market with one window setting, so it shows what the number looks like, not what to expect from your strategy. It also shows the kind of year the count catches: four of five above zero, with one year near zero, and no year that erased the others.
How do you run the same test on a grid of window settings?
Because window lengths are choices too, run a matrix of in-sample and out-of-sample lengths and trust a strategy that behaves similarly across most cells, not one that survives only a single combination. The 36-month and 12-month lengths in the run above were a decision, and a different decision would have given a different joined result. A walk-forward matrix is a grid of walk-forward runs, one for each combination of in-sample length and out-of-sample length, with everything else held fixed.
The reasoning is the same one you applied to parameters. A setting that works only at one exact value is suspicious, so you look for a broad region. Window lengths are parameters of the test itself, and a strategy that only passes at 36/12 and fails at 24/12 or 36/6 has told you that its result depends on where the cuts fell, not on the rule.
- Fix everything except the window lengths: the parameter ranges, the objective, the selection rule, rolling or anchored, and the costs. These stay identical in every cell.
- Choose a small grid. In-sample lengths of 2, 3 and 4 years against out-of-sample lengths of 3, 6 and 12 months give nine cells and cover a 2:1 to 16:1 range of ratios.
- Run every cell and record for each one the joined out-of-sample result, the count of positive windows, the worst window and the efficiency.
- Read the grid as a picture, not as a list of winners. Similar shading across most cells is the result you want. One bright cell in a dull grid is a warning that you found a lucky cut.
Hypothetical example
Strategy A passes in seven of nine cells, with joined out-of-sample results of the same sign and efficiency between roughly 50% and 80% in those seven; the two cells that fail are both at the shortest in-sample length, where the windows hold too few trades. Strategy B passes in exactly one cell, 36 months by 12, and is near zero or negative in the other eight. Strategy A has shown that its result does not depend on where the windows were cut. Strategy B has shown the opposite, even though its one passing cell might look better than any cell of A.
A matrix is expensive, because every cell is a full set of optimizations. Nine cells with five or more windows each, over a nine-combination parameter grid, already means hundreds of backtests for one strategy, and a real parameter space is usually much larger than nine combinations. How long that takes depends on the processor or graphics card, the data length and the research settings. The practical consequence is that the matrix is where many traders stop testing thoroughly, and knowing that in advance is a reason to plan the grid before the first run rather than add cells one at a time when a result disappoints.
Can walk-forward analysis still be overfitted?
Yes: running many walk-forward tests and keeping the best one re-introduces selection bias, so fix the settings in advance, count every trial, and follow the surviving out-of-sample trades with a Monte Carlo backtest and robustness testing. Walk-forward analysis protects you from one kind of hindsight, the kind inside each window. It does not protect you from hindsight applied to the walk-forward runs themselves.
The mechanism is simple. Suppose you run twenty walk-forward tests with different objectives, selection rules, window lengths and parameter ranges, and you publish the one with the best joined out-of-sample result. That result is no longer out of sample. You chose it after seeing it, which is exactly what the method was built to prevent, one level up. Bailey, Borwein, López de Prado and Zhu (2014) show that the more configurations a researcher tries, the more history is needed before the best one means anything at all, and that researchers who do not report the number of trials leave the reader no way to judge the result. Harvey and Liu (2015) make the same point about Sharpe ratios: a result that looks strong after one trial can be unremarkable after dozens, and the honest way to read it is to count the trials and discount accordingly. The matrix in the previous section is itself a set of trials, which is why its reading rule is "most cells similar", never "the best cell".
Four habits keep the test honest:
- Write the settings down before the first run: objective, ranges, selection rule, interval, rolling or anchored, and the grid of window lengths. A setting changed after a result is a trial, and it counts.
- Keep a count of every walk-forward run on the strategy, including the ones you discarded. The count is part of the result, not a footnote.
- Read the whole grid, not the best cell, and report the worst window and the parameter history alongside the joined total.
- Treat the surviving out-of-sample trades as the input to the next test, not as the end of testing.
Two tests take those trades further. A Monte Carlo backtest reshuffles the order of the out-of-sample trades many times to show how deep the drawdown could have been if the same trades had arrived in a different sequence; the free Monte Carlo simulator does this from a pasted list of trade results. Robustness testing then disturbs the inputs rather than the order: it doubles the slippage, shifts the parameters a step away from the picked values, and moves the start date, and asks whether the result survives. A strategy that passes walk-forward, keeps its drawdown within reach under Monte Carlo, and does not fall apart when its inputs are nudged has been tested the way it will be traded. The same selection trap at the level of strategy generation, where thousands of candidates are searched and the survivors are then tested, is covered in overfitting in strategy generation.
Frequently asked questions
What does WFA mean in trading?
WFA stands for walk-forward analysis. It is a backtest method that optimizes a strategy's parameters on one window of past data, trades the frozen parameters on the following window, then moves forward and repeats. The out-of-sample windows are joined into one result, and that joined result is the only backtest number that could have been traded in real time.
Is walk-forward validation the same as walk-forward analysis?
In practice the two terms describe the same test: repeated optimization on in-sample windows followed by frozen trading on out-of-sample windows. "Validation" stresses the purpose, which is to check whether an optimized strategy holds up on unseen data. "Analysis" stresses the reading of the results, such as the count of positive windows, the parameter history and the walk-forward efficiency.
What is a good walk-forward efficiency?
Walk-forward efficiency is the out-of-sample profit per month divided by the in-sample profit per month across all windows. Many traders treat half or more as acceptable and a small fraction as a sign that the optimizer fitted noise. The measured NQ run in this article reached 94% on five rolling windows, but that run is long only on a market that rose over the period, which lifts both sides of the ratio, so the number should be read with the market move in mind.
Does a positive walk-forward result mean the strategy will make money?
No. A positive joined out-of-sample result shows that a specific re-tuning process worked on the history you tested, with the costs you included. It does not show what the next year will do, and it loses its meaning if it was the best of many walk-forward runs. Treat it as the first number worth judging, then test the out-of-sample trades further with a Monte Carlo drawdown test and robustness checks.
How much data do I need for walk-forward analysis?
Enough for at least four or five out-of-sample windows after the first in-sample window, where the in-sample window holds at least 30 to 50 trades. With 36 months in-sample and 12 months out-of-sample, five windows need eight years of data. A strategy that trades rarely needs a longer in-sample window and therefore more history, while a strategy that trades often can use shorter windows and fit more of them into the same data.
References
- Pardo, R. (2008). The Evaluation and Optimization of Trading Strategies (2nd ed.). John Wiley & Sons.
- Bailey, D. H., Borwein, J., López de Prado, M., & Zhu, Q. J. (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society, 61(5), 458–471.
- Harvey, C. R., & Liu, Y. (2015). Backtesting. The Journal of Portfolio Management, 42(1), 13–28.

