Learn › Glossary › Walk-Forward Analysis

Walk-Forward Analysis

Repeatedly optimizing a strategy on one window of history and testing it on the next unseen window, rolling forward through time. It simulates how a periodically re-tuned strategy would actually have been experienced, and exposes parameter sets that only worked in one regime.

Walk-forward analysis is a way of testing a strategy that has settings to tune. You pick a stretch of history, find the settings that worked best on it, then run those settings on the next stretch of data the tuning never saw. You record that second result and slide both stretches forward in time, then repeat. The out-of-sample results, joined together, are the walk-forward record. It answers a narrower question than an ordinary backtest: if I had re-tuned this strategy on a schedule and traded the result, what would I have got?

An ordinary backtest picks one set of parameters and reports the best-looking history for it. A walk-forward test only gives credit for the periods the parameters were not fitted to. It is closely tied to out-of-sample testing, which holds back data once, and to overfitting, the problem both methods exist to expose. The answer on avoiding overfitting a backtest places walk-forward among the other defences.

DeployQuant's own market data shows why the method matters. The window is 2021-01-04 to 2026-10-02, about 5.74 years of minute data on 59 ETFs. The numbers below describe how SPY, QQQ, TLT, TQQQ, IWM and UVXY behaved in each year of that window, and how much the behaviour changed from one year to the next. That change is the reason a rule tuned on one year can fail in the next.

The backtests in the Learn library are not walk-forward tests. The 12 templates have fixed parameters, run once over the whole window, and the pages show them with nothing hidden: every trade, every drawdown and a set of parameter variants. Walk-forward is a tool a strategy author applies on top of that.

How a walk-forward run is laid out

A walk-forward test has four pieces: a training window, a test window, a step and a parameter grid. The training window is the span of data used to choose settings. The test window is the span right after it, where the chosen settings trade without any further tuning. The step is how far both windows move before the next round. The grid is the list of settings tried on each training window, for example RSI thresholds of 20, 30 and 40.

On this dataset the calendar gives a natural layout. The window covers 2021, 2022, 2023, 2024, 2025 and part of 2026. One layout trains on two years and tests on the next one. The first round would tune on 2021 and 2022 and trade 2023. The second would tune on 2022 and 2023 and trade 2024. The third would tune on 2023 and 2024 and trade 2025. After that, 2026 is a partial test year. Three or four test results is a small number, and it is also what a window of 5.74 years can support.

There are two common versions of the layout. A rolling walk-forward keeps the training window the same length and drops the oldest data as it moves. An anchored walk-forward always starts the training window at the first date and extends it with each round. A rolling window adapts faster to a change in the market and uses less data per fit. An anchored window uses everything and changes slowly. Neither is correct in general, and the choice is a judgement about how fast the market the strategy trades is changing.

The out-of-sample results are stitched together in time order to make one equity curve. That curve is the evidence. Its CAGR, its drawdown and its trade count are compared with the in-sample figures from the same rounds. If the strategy earned a high return in each training window and a much lower one in each test window, the settings were fitted to noise.

Why one window's best settings fail in the next

The market in each year of this dataset looked different, and the differences are large. SPY returned 30.46% in 2021, then lost 18.16% in 2022, then gained 26.18% in 2023. QQQ made 29.18%, lost 32.39% and gained 54.81% over the same three years. A strategy tuned on 2022 sees a market where buying dips loses and trend filters help. A strategy tuned on 2023 sees the reverse. Parameters chosen on either year carry that year's character into the next one.

TQQQ makes the point more sharply. It returned 90.95% in 2021, lost 79.07% in 2022 and gained 198.32% in 2023, then returned 58.22% in 2024, 34.36% in 2025 and 54.6% so far in 2026. Its max drawdown over the window was 81.68%, from 2021-11-19 to 2022-12-28, and it recovered on 2024-12-04. Settings tuned inside that drawdown, say a tight stop that avoids the fall, could look excellent on the training years and give up part of the 2023 rebound on the test year. A walk-forward test makes that cost show up in the record, where a single backtest would hide it.

TLT shows what happens when a market has one direction for the whole window. It lost 8.64% a year, with a 44.06% max drawdown from 2021-01-04 to 2023-10-19 and no recovery by 2026-10-02. It spent only 35.18% of sessions above its 200-day average and crossed that average 95 times. A trend rule tuned on its early years would see persistent weakness, and a rule tuned on any one year would see an asset that rarely made a durable move up. A walk-forward test across those years would show rules that were consistent, with the same sign in each fold, which is a good sign, and rules that flipped, which is a bad one.

UVXY is the extreme. Its CAGR was -72.83%, its max drawdown was 99.95% and it ended with $215.70 from $10,000 held. It lost between 3.1% and 88% in each calendar year of buy-and-hold. In this case every training window would say the same thing, yet the settings would still need to deal with a fund that spiked sharply, 30.46% in April 2022, against a steady decay.

SPY and QQQ spent 77.99% and 75.18% of sessions above the 200-day average, and crossed it 30 and 20 times. IWM spent 63.29% above it and crossed 34 times. Those figures describe how much trend a rule had to work with in each fund over the whole window. A walk-forward test splits that into pieces and shows whether the share of time in trend was stable from one piece to the next. The 2022 decline falls inside only one or two of the pieces, so the pieces differ a great deal.

What a walk-forward test does to an indicator rule

Consider an RSI rule on SPY. RSI(14) was below 30 on 18 sessions in the whole window, and the median 5-day return after those sessions was 3.74% against a baseline median of 0.42% for any 5-day span. The 20-day figure was 2.86% against 1.73%. With 18 sessions, those readings sit in a handful of episodes. If a walk-forward test splits the window into folds, some folds contain 2 or 3 such sessions and some contain none. The tuned threshold of 30 would then be an estimate built on a few observations per fold, and the test would report a very uneven result across rounds.

The shorter RSI(2) rule has more to work with. RSI(2) was below 10 on 146 SPY sessions, with a median 5-day return of 0.89% and a median 20-day return of 2.29%, and it was below 10 on 144 QQQ sessions. A walk-forward test has far more observations per fold, so the choice of threshold is better supported. The RSI(2) snapback template made a median of 166 round trips per fund in the window, which is why its results rest on more data than a rule that trades three times.

QQQ's RSI(14) was below 30 on 15 sessions with a 5-day median of 3.69%, but its 20-day median was only 1.42% against a baseline of 1.74%. On those sessions the bounce showed up in a week and then faded. TQQQ was below 30 on 18 sessions with a 5-day median of 10.3% and a 20-day median of 6.9%. TLT was below 30 on 61 sessions and the 5-day median was 0.02%, while the 20-day median was -1.63%, and UVXY at 116 sessions had -1.79% and -5.82%. The same indicator level meant a bounce on one fund, nothing on another, and a continued fall on a third. A threshold tuned on one fund and applied to another would face a different response, and the figures above show how different it can be.

The point for walk-forward is that the same parameter can be the right choice on one training window and the wrong one on the next. If the walk-forward record shows a different best threshold in each round, the strategy has no stable setting, and the aggregate out-of-sample result usually shows it.

Choosing the window sizes

A short training window fits recent conditions and has few observations. A long one has many observations and mixes regimes. The window of 5.74 years makes this concrete. A 1-year training window on this data is one regime: 2022 alone has SPY down 18.16%, and 2023 alone has it up 26.18%. A 3-year window mixes a rise, a fall and a rebound.

The test window has the opposite trade-off. A long test window gives a more reliable out-of-sample figure and delays the next re-tune. A short test window re-tunes often and produces many noisy results. For a strategy with 3 trades in the whole window, any test window shorter than the whole window has 0 or 1 trade in it, and the result says nothing.

The trade count sets a floor. A rule needs enough trades in each training window to estimate its settings and enough in each test window to report a result. The medians in the library show the range. The golden cross made 3 round trips per fund, the dip buyer made 2, the trend with trailing stop made 4 and the momentum breakout made 6. Walk-forward testing those rules over a window of this length gives one or two trades per fold. The monthly cycle made 69, the weekly 7% target made 106 and the RSI(2) snapback made 166, and those rules have enough trades per fold to be tested this way.

Each fold also pays a cost in data. Every training window removes history from the final test record, and an anchored layout keeps the first fold's training data out of the result entirely. On a short dataset, the share of history that counts as out-of-sample is smaller than the share that is used for fitting.

What walk-forward does not fix

Walk-forward is a stronger check than a single backtest, and it has limits. It does not remove the risk of overfitting. It tests one procedure, and if the author tries 20 procedures and keeps the one with the best walk-forward result, the procedure has been fitted to the walk-forward record. The test only protects the author who runs it once.

It does not protect against a regime that never appears in the data. This window contains one large decline, 2021 into 2022, for the equity funds. SPY's drawdown ran from 2022-01-03 to 2022-10-12 and recovered on 2023-12-13, with 488 sessions in its longest drawdown. QQQ's longest was 516 sessions. A walk-forward test of any rule on this window has one fold, at most two, that contains the decline. A rule that survived it has been tested on one bear market.

It does not model costs unless the engine does. The headline runs in the library have no fees or slippage, and each page also shows runs at 5 and 10 basis points. A rule that makes 166 round trips is affected by that choice much more than one that makes 3, and a walk-forward result without costs is an upper bound.

It does not account for the market changing after the data ends. The out-of-sample record shows what happened in periods that were unseen by the tuning and are still in the past. Paper trading on the live feed is the one test where the data truly has not happened yet, and DeployQuant offers it without a broker. The product reference also describes a decision log for each trade, so a paper run can be compared with the backtest trade by trade.

Finally, the method is slower than a single run. Each fold repeats the grid search, so a grid of many settings over many folds multiplies the number of backtests. A multi-year minute backtest on DeployQuant finishes in seconds, which keeps a grid of this kind practical, and the library's pages each show a few parameter variants as a quick check of sensitivity.

A cheaper check: how much do the results move with the settings

A full walk-forward test needs a grid and a schedule. A smaller check asks how much the result changes when the parameters move a little. If a template's CAGR swings widely when a threshold changes by a small amount, the best setting is likely to be an artifact. Each backtest page in the library lists variants of its parameters next to the headline run, and the page on any fund is the place to read them.

The medians across the 12 templates give a feel for the spread in outcomes by design. The weekly 7% target had a median CAGR of 6.61% and a median max drawdown of 26.26%. The monthly cycle had 5.46% and 36.63%. The RSI(2) snapback had 4.74% and 17.47%. The RSI mean reversion template had 2.98% and 24.63%. The EMA 12/26 trend had 2.76% and 22.87%, the trend with trailing stop had 2.61% and 31.15%, and the SMA 10/50 trend had 2.12% and 23.02%. The golden cross had 2.05% and 21.84%, the 200-day regime filter had 1.84% and 22.16%, and the dip buyer had 1.33% and 26.19%. The momentum breakout and the 3-month momentum rules both had a median CAGR of 0%.

These are single-window results, and a walk-forward version would produce a different number for each. They also show that the gap between the top and the middle of the list is a few points of CAGR, and that gap is the size of what one regime change can move. The number of funds that beat buy-and-hold ranges from 14 for the monthly cycle to 34 for the weekly target and the RSI(2) snapback. A strategy whose rank flips between folds belongs near the middle of that list, whatever its full-window figure says.

Frequently asked questions

What is walk-forward analysis?

It is a test that repeatedly tunes a strategy's settings on one window of history and then trades those settings on the next window, which the tuning never saw. The out-of-sample results from every round are joined into one record. That record shows how a strategy that was re-tuned on a schedule would have done.

How is walk-forward different from out-of-sample testing?

Out-of-sample testing holds back data once, usually the latest part. Walk-forward does it many times and moves the split forward through history. The [out-of-sample entry](/learn/glossary/out-of-sample/) covers the single split.

Does walk-forward testing prevent overfitting?

It reduces the chance that a strategy's headline number comes from fitting noise. It does not remove the risk. An author who tries many procedures and keeps the best walk-forward result has fitted the test itself. See [overfitting](/learn/glossary/overfitting/).

How long should the training and test windows be?

There is no single answer. On this dataset of 5.74 years, SPY lost 18.16% in 2022 and gained 26.18% in 2023, so one-year windows each capture one regime. The window also has to hold enough trades: the golden cross made 3 round trips per fund and the RSI(2) snapback made 166.

Are the backtests on DeployQuant's Learn pages walk-forward tests?

No. The 12 templates use fixed parameters over the whole window from 2021-01-04 to 2026-10-02. Each backtest page shows parameter variants, cost runs and every trade, so a reader can judge how sensitive the result is.

What is the difference between rolling and anchored walk-forward?

A rolling test keeps the training window at a fixed length and drops old data as it moves. An anchored test starts at the first date and grows. The rolling version adapts faster and the anchored version uses all the data.

Can I paper trade a strategy as a final out-of-sample check?

DeployQuant paper trades on the live market data feed without a broker. Data that has not happened yet is the cleanest out-of-sample test, and the [avoiding overfitting answer](/learn/answers/avoid-overfitting-backtest/) discusses how it fits with the other checks.

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…OverfittingTuning a strategy until it fits the historical data's noise rather tha…

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.