How to use rolling windows in a backtest
A rolling-window backtest repeats one frozen thesis across a sequence of equal-length date ranges. Move the start and end dates forward by a fixed step, keep every other setting unchanged, and compare the result from window to window. The test shows whether an apparent edge persisted through time or lived inside one fortunate stretch.
Use rolling windows after you've settled the thesis and a primary result to read. They don't create fresh independent histories, and they don't repair a thesis tuned on the whole sample. What they do well is expose dependence on the calendar. One full-period return can hide that dependence completely.
What does a rolling-window test ask?
A conventional backtest gives you an answer over one chosen span. Change the first date and you change the companies eligible for selection, the filings available, the market environments included, and the time each event has to mature. The result may move because the underlying relationship moved. It may also move because one unusual episode entered or left the sample.
A rolling window fixes the span and shifts it through the history. You might use a window five years long and advance it one year at a time. Those are research settings, chosen before you inspect the sequence. Each run asks the same question over a later slice of the record.
The useful output isn't an average of all the windows. It's the path:
- Does excess performance keep the same sign?
- Do drawdowns worsen in a recognizable part of the history?
- Does the number of qualifying events collapse in some windows?
- Does one window account for most of the full-period result?
This is different from testing a thesis across named market regimes. A regime test starts with an economic condition, such as a published rate series. A rolling-window test starts with the calendar and asks when the conclusion held. The windows can suggest a mechanism to investigate, but they don't name one for you.
Freeze the thesis before moving the dates
Keep the thesis version, universe, benchmark, rebalance schedule, reporting lag, entry rule, exit rule, and primary statistic fixed. Only the date range should move. If you loosen a leverage gate in a weak window and restore it for the next one, you're comparing different theses.
Write the plan first. The shape below is illustrative. The numbers are proposed research parameters, and the bundled templates plus the Quantery documentation are the reference for supported thesis fields.
# Rolling-window plan: illustrative
thesis_version: quality-value-v7
benchmark: SPY
rebalance: monthly
reporting_lag_days: 1
entry: next_close
exit: { max_hold_months: 12, on_gate_fail: true }
windows:
length_years: 5
step_years: 1
primary_read:
event_horizon_months: 12
statistic: median_excess_return
The five-year length and one-year step aren't defaults. A narrow thesis with few qualifications may need a longer span. A rule that produces frequent observations can be read over a shorter one. Pick a window long enough to include several decision cycles, then refuse to shorten it because a weak result looks better when cropped.
The step controls how much adjacent runs overlap. A shorter step gives you a smoother view of when the result changed, but it repeats more of the same observations. A longer step repeats less data and gives you fewer windows. Neither setting creates a new market history.
Choose the primary read too. Median excess return at a fixed event horizon asks something different from terminal portfolio return. Maximum drawdown asks something different again. If you switch panels whenever a window disappoints, the sequence becomes a search for whichever statistic survived.
Overlapping windows aren't independent evidence
Suppose two adjacent windows share most of their dates. They'll share many filings, prices, qualification events, and market shocks. Similar results across the pair may come from the shared observations. Counting each window as a separate confirmation would multiply the evidence on paper without adding much history.
That's why the sequence should be read as a diagnostic path. Look for transitions. If a result weakens as one episode rolls out of the window, inspect that episode. If it improves as coverage deepens, the change may belong to the dataset. If every overlapping run keeps the same direction, that's encouraging, but it isn't the same as repeating the test in a new market.
Run a second pass with non-overlapping windows when the available history permits. Those blocks still belong to one historical path, and businesses can appear in more than one block. They do reduce the mechanical duplication caused by overlap. If the overlapping path looks stable while the non-overlapping blocks disagree sharply, the smoothness came partly from reusing the same dates.
Don't turn every start date into another vote. The statistical problem is the same one behind backtest overfitting: repeated specifications give chance more opportunities to produce a result you like. Bailey, Borwein, López de Prado, and Zhu show why trying multiple backtest configurations raises the odds of selecting a lucky one. A rolling study becomes another parameter search if you publish the best window and hide the sequence.
Read coverage before you read returns
Calendar stability and data stability aren't the same thing. An early window can contain fewer usable filings, thinner price history, or a reconstructed universe. A later window may evaluate a much fuller market. If the result changes at the same time as coverage, you haven't isolated an economic change.
Start each run with the coverage note. Record the effective date span, missing-field behavior, and whether the thesis had enough qualifying events for the declared horizon. Checking data coverage before a backtest is part of the experiment, since a date printed in the selector doesn't guarantee a comparable observation set.
Keep the information clock intact too. Fundamentals enter only after the filing became public, plus any reporting lag in the plan. A rolling run must use the figures available on each simulated date. Point-in-time data and filing-date alignment still apply when the calendar moves.
Macro variables need the same treatment if they're inside the thesis or used to explain the windows. Current databases often contain revised historical readings. The Federal Reserve Bank of St. Louis built ALFRED to preserve data vintages as they were available on earlier dates. Using the final revised series can give an old decision information it couldn't have had.
A sparse window isn't a failed thesis. It's an unreadable window. Mark it that way. Extending just that one range until enough observations appear changes the design after seeing the problem.
Compare the path in layers
Read every window in the same order.
First, check coverage and event maturity. A qualification near the window's end may lack the full forward period required by your primary event statistic. Compare like with like, or shorten the reporting endpoint for every window under one predeclared rule.
Second, check direction versus the benchmark. Excess return means the thesis result minus the recorded benchmark result over aligned dates. Backtest returns are hypothetical and exclude costs. Don't compare a thesis line from one window with a benchmark line from another.
Third, inspect dispersion. Median event return can stay positive while a portfolio result depends on one large winner. A stable average with an unstable median tells a different story. Keep the declared statistic primary, then use the others to diagnose why runs disagree.
Fourth, inspect composition. Did the thesis select the same sectors and size range throughout? A calendar break may be a hidden change in exposure. Test whether the thesis is carrying a sector bet, especially when one industry's cycle lines up with the strong windows.
Finally, check drawdown and turnover. A direction that persists with much worse drawdown may still describe a materially different implementation. Higher turnover matters because the reported results exclude trading costs and taxes.
Save the sequence as a research record. For each run, keep the thesis version, dates, coverage note, event count, benchmark, primary statistic, drawdown, and turnover. The rows should make an inconvenient window as visible as a good one.
What should you do when a window breaks?
Don't repair the window. Diagnose it.
First rule out mechanics: changed thesis version, mismatched benchmark, missing data, a different effective universe, or immature events near an endpoint. A mechanical mismatch says nothing about the business claim.
Then ask what entered and left. If a strong result disappears when one market episode rolls out, test that episode as a concentration problem. Remove it from the other windows under the same rule and see whether the broader conclusion survives. Don't delete it only from the weak run.
Next inspect the selected companies. A thesis can keep identical equations while drifting into a different sector or size bucket as relative valuations change. If composition explains the break, restate the finding in those terms. The original business mechanism hasn't earned the credit yet.
You can also compare neighboring round thresholds, but do that across the full window sequence. Changing a cutoff only where the baseline fails is fitting the calendar. One-dial perturbation should challenge every run with the same variant.
A break may be the result. If the thesis held through earlier windows and failed through later ones despite comparable coverage and composition, its edge may have decayed. That deserves a new hypothesis about competition, valuation, accounting, or implementation. It doesn't justify erasing the later dates.
Rolling windows don't replace a holdout
A holdout period is kept unseen while the thesis is built, then used once after the rules are frozen. Rolling windows usually expose every part of the available history. Once you've studied the path and changed the thesis because of it, those dates have joined development.
Use the tools in sequence. Develop the thesis on an early sample. Run perturbations and rolling windows there to learn whether the conclusion depends on settings or calendar placement. Freeze the rules. Then spend a genuinely untouched holdout on the finished process.
If you already designed the thesis after seeing the full history, say so. The rolling sequence can still reveal fragility, but it can't recreate blindness. Replay isn't erasure.
The clean conclusion from a rolling study is narrow: these frozen rules produced this pattern across these fixed windows, under this coverage, before costs. A stable path earns the thesis another test. An unstable path tells you where to look. Keep all the windows, including the ugly one. The calendar is a parameter too, and the rules are yours to move only after you've recorded what happened before the move.
Research tooling, not investment advice. Nothing here is a recommendation to buy, sell, or hold any security. Screens, scores, and backtests are informational only; backtested results are hypothetical, exclude costs such as commissions and slippage, and do not guarantee future results. Verify against primary filings and make your own decisions.
Want to try this on your own rules? Quantery is free for 14 days: the full app, no card required.
← All articles