Skip to content

GuideReal edge or luck

Walk-forward analysis: how it works, with a 10-window example

Walk-forward analysis tunes a strategy on one stretch of history, tests it on the next stretch the tuning never saw, and repeats. The evidence is the joined test windows, not the tuned results.

Key takeaways

  • Judge the joined test record, not the tuning results: in the made-up example, $36 a trade in tuning became $4 a trade out of sample.
  • Walk-forward efficiency (out-of-sample result divided by in-sample result) is a quick summary, but the common 50% mark is a rule of thumb, so read it next to the window-by-window results.
  • Window lengths and the tuning rule are settings too: choose one layout up front instead of trying several and keeping the best-looking one.

Walk-forward analysis (also called walk-forward optimization) is a way to test a trading strategy by tuning its settings on one window of history, testing them on the next window the tuning never saw, then sliding forward and repeating. The test windows are joined into one out-of-sample record (results on data the tuning never saw). That record, not the tuned results, is the evidence: it shows how the strategy would have done if you had re-tuned it on a fixed schedule.

Robert Pardo set out the method for traders in his 1992 book on designing and testing trading systems (walk forward optimization on Wikipedia).

How does a walk-forward test work?

A walk-forward test repeats one loop: tune on an in-sample window, trade the winning settings untouched on the out-of-sample window right after it, then move both forward by the length of that test window.

Walk-forward testing
Each round tunes on one window and tests on the next window the strategy hasn’t seen, then moves forward. Holding up round after round is much stronger evidence than one good split.
  1. Seal the end first. Set aside the last stretch of history; the walk-forward never touches it.
  2. Fix the layout. Choose rolling windows (the tuning window keeps its length and slides) or anchored ones (it starts at the first bar and grows). Then pick the tuning window (in-sample data), such as two years; the test window (out-of-sample data), such as six months; and the tuning rule, such as “the stop size with the best average trade after costs”.
  3. Tune on the first tuning window and pick the winner by your rule.
  4. Trade the winner untouched on the test window right after it.
  5. Slide forward by the length of the test window, and repeat until you reach the sealed stretch.
  6. Join the test windows into one out-of-sample record, and judge that.

A walk-forward analysis example, window by window

In this made-up 10-window example, a stop setting that averaged $36 a trade in tuning averaged $4 a trade across the joined test windows. The strategy has one setting, its stop size, tried at 6, 8 and 10 points. The history is seven years of invented results before a sealed final year (not shown), 100 trades a year, all after costs. Each round tunes on the latest 24 months and tests on the next 6, which gives ten test windows of about 50 trades each.

Window Months: tune → test Stop picked Tuning result per trade Test result per trade
1 1 to 24 → 25 to 30 6 points $40 $15
2 7 to 30 → 31 to 36 6 points $38 $10
3 13 to 36 → 37 to 42 6 points $35 $20
4 19 to 42 → 43 to 48 8 points $36 −$10
5 25 to 48 → 49 to 54 10 points $42 −$25
6 31 to 54 → 55 to 60 10 points $40 $5
7 37 to 60 → 61 to 66 8 points $30 $10
8 43 to 66 → 67 to 72 8 points $32 $0
9 49 to 72 → 73 to 78 6 points $34 $15
10 55 to 78 → 79 to 84 6 points $33 $0
Average $36 $4

Read the last column, not the one before it. Every tuning window found a stop that averaged $30 to $42 a trade. Joined end to end, the ten test windows average (15 + 10 + 20 − 10 − 25 + 5 + 10 + 0 + 15 + 0) ÷ 10 = $4 a trade over 500 trades.

The best stop also changed from 6 to 8 to 10 points and back. A changing pick isn’t a warning by itself: if all three stops score within a dollar or two in tuning, any can win by a hair, and that’s a healthy plateau of settings. Here, the two losing windows (4 and 5) are the two where the pick moved wider, so look at their tuning results. Say window 5 scored the 10-point stop at $42 and the others at $24 and $22: one setting far above the rest is the mark of a lucky spike, not a plateau.

What is walk-forward efficiency?

Walk-forward efficiency is the out-of-sample result divided by the in-sample result, written as a percentage. Annualized returns are the usual inputs; per-trade figures work too when the tuning and test windows trade equally often. In the example it’s $4 ÷ $36, about 11%: most of the tuned performance didn’t survive.

Did it survive? Four checks on the joined record

Four checks give a first read on a walk-forward: efficiency, how many windows made money, whether one window carries the total, and whether there are enough trades. Applied to the example:

  1. Efficiency: about 11%. Far below even the 50% rule of thumb.
  2. Winning windows: 6 of 10. Two more broke even and two lost.
  3. One window carries it. Window 3 made $1,000 (50 trades at $20) of the $2,000 total; the other 450 trades average about $2.22.
  4. Not enough trades. With trades spreading about $120 around the average (made-up), the rule in how many trades a backtest needs asks for about (1.64 × 120 ÷ 4)² ≈ 2,400 trades, nearly five times the 500 here.

So for the example, $36 a trade in tuning shrank to $4 out of sample, and half of that profit came from one window. As it stands, this isn’t evidence of an edge.

Anchored vs rolling walk-forward: what’s the difference?

A rolling walk-forward keeps the tuning window the same length and drops the oldest data as it moves. An anchored one keeps the start fixed, so the tuning window grows every round. Neither is better in general: pick the one that fits how you expect the edge to behave.

Feature Rolling Anchored
Tuning window Fixed length, slides Grows from the first bar
Fits an edge you expect to Drift as markets change Stay much the same for years
Goes wrong when Short windows chase recent noise Old years outweigh recent change

Coding it? scikit-learn’s TimeSeriesSplit is anchored by default; capping max_train_size makes it rolling once the cap is reached.

How long should the windows be?

Each tuning window needs enough trades to pick a setting from, and each test window enough trades to add to the record. You also need enough windows that one lucky or unlucky stretch can’t decide the result.

  • Tuning window: long enough that every setting you try is judged on a real sample, and long enough to hold more than one kind of market.
  • Test window: TradeStation’s guide suggests tuning-to-testing ratios from 3:1 to 9:1, so the test is 10% to 25% of each round, with 20% as its default. The example’s 24 and 6 months is 4:1, or 20%.
  • Number of windows: the same guide says it takes at least 10 runs before a walk-forward starts to be reliable.

What can’t walk-forward analysis tell you?

Walk-forward analysis can’t tell you that the next window will look like the last ten. All its windows come from one path through history, and the settings you’d trade next haven’t been tested at all.

  • It’s still one path. Daniel Palomar’s textbook Portfolio Optimization points out that a walk-forward run is still a single backtest over a single historical path, so it can still be overfit (section 8.4). The first tuning window is never tested at all: in the example, only 60 of the 84 months are judged.
  • The next settings are new. After the last window, you re-tune on the latest data and trade settings no test window has seen. The walk-forward record judges your tuning routine, not those exact numbers.
  • Mistakes carry through. Unrealistic costs and fills, or look-ahead bias inside a window, flow straight into the joined result.

Which settings do you trade after a walk-forward?

A failed joined record ends this rule and layout; a passing one earns one look at the sealed stretch.

If it fails, note that this rule and layout didn’t hold, and move on. Rerunning with new windows would tune on the test windows.

If it holds, open the sealed test once. If that holds too, the settings to watch are the ones your rule picks on the latest tuning window, re-tuned on the same schedule (every six months in the example). The evidence is about that routine, so changing the rule leaves you with settings the evidence doesn’t cover. Let them trade on paper as new bars arrive, changing nothing.

If you’d rather not build the windows yourself, Kwaant runs walk-forward analysis among its checks. It covers ES and NQ (S&P 500 and Nasdaq-100 futures) strategies you describe in plain English.

Sources and further reading

Questions people ask

What is the difference between walk-forward analysis and walk-forward optimization?

Many traders use the two names for the same test. Some writers separate them: walk-forward optimization is the repeated re-tuning, and walk-forward analysis is the whole test, including judging the joined out-of-sample results.

Is walk-forward testing the same as forward testing?

Usually not, though some sources, Wikipedia among them, use “walk-forward testing” to mean forward testing. A walk-forward test runs entirely on past data, so it can test your re-tuning routine across many windows in one go. A forward test is the first time the settings you’d actually trade meet data that didn’t exist when you chose them.

What is walk-forward validation?

Walk-forward validation is the machine-learning name for the same idea: train on earlier data, check on the next block, and roll forward. Forecasters call it time series cross-validation, or evaluation on a rolling forecasting origin (Hyndman and Athanasopoulos, Forecasting: Principles and Practice).

Does walk-forward analysis prevent overfitting?

It makes overfitting easier to spot, but it doesn’t prevent it. Each test window is unseen by its own tuning, yet you can still overfit by trying many strategies, window layouts or tuning rules and keeping the one whose walk-forward looks best.

General education about testing strategies, not investment advice. Figures are computer-drawn illustrations, not real market data.