Moving Window
- Category
- Quantitative Finance
- Level
- Professional
Simple definition
A fixed-length slice of recent data that slides forward one step at a time. Every statistic computed inside it is recomputed as the slice moves.
Professional definition
A device for making a statistic time-varying: a rolling window keeps the last w observations and drops the oldest at each step, while an expanding window keeps everything from the start. The window length sets the trade-off between responsiveness and estimation noise.
Technical definition
A rolling estimator evaluates a function on observations t minus w plus one through t, so it has constant memory and a constant effective sample. An expanding estimator evaluates it on observations one through t, so its variance falls over time but it never forgets a past regime. Both are causal only if the window ends at t; a window centred on t consumes future observations and is unusable in live trading.
Academic definition
A localising scheme in which an estimator is evaluated repeatedly over successive fixed-length or cumulative subsamples, producing a time-indexed sequence of estimates.
Mechanism
A window imposes a memory length. Short windows re-estimate from few observations, so they track a regime change quickly but carry large sampling error; long windows are stable but average across regimes that no longer apply. The choice is not a tuning detail, it is a statement about how fast the process is assumed to change.
In practice
- Who uses it
- Indicator designers, volatility modellers, walk-forward testers, and anyone computing a rolling Sharpe ratio, beta or correlation.
- Why it matters
- It is the only way to let a parameter respond to a changing market while keeping the computation reproducible at every historical date.
- Limitations
- Every rolling estimate is correlated with its neighbours because consecutive windows overlap, so a rolling series has far fewer independent observations than it has points.
Common mistakes
- Centring the window, which reads bars that had not printed yet.
- Choosing the window length by whichever value backtests best.
- Treating overlapping rolling values as independent observations.
Examples
Closes 10, 12, 11, 13, 15, 14, 16. The rolling three-bar mean reads 11, 12, 13, 14, 15. The expanding mean reads 10, 11, 11, 11.5, 12.2, 12.5, 13 — still carrying the first bar at the end.
- closes = [10, 12, 11, 13, 15, 14, 16]
- rolling window w = 3
- expanding window starts at the first bar
- rolling: (10+12+11)/3 = 11; (12+11+13)/3 = 12; (11+13+15)/3 = 13; (13+15+14)/3 = 14; (15+14+16)/3 = 15
- expanding: 10; (10+12)/2 = 11; 33/3 = 11; 46/4 = 11.5; 61/5 = 12.2; 75/6 = 12.5; 91/7 = 13
The rolling mean reaches the latest level; the expanding mean lags it permanently because the early low closes never leave the sample.
A twenty-one bar average centred on the current bar uses ten bars that have not printed. It smooths beautifully in a backtest and cannot be computed live, so the strategy's reported edge is an artefact of reading the future.
Mathematical foundation
Variables
| w | Window length in periods | periods |
| f | Any statistic: mean, standard deviation, beta, correlation | depends on f |
| x_t | Observation at time t | depends on series |
| \hat{\theta}_t | Estimate attributed to time t | depends on f |
Procedure
Fix the window length and the alignment. At each date t, collect the observations the window covers, apply the statistic, and stamp the result at t — never at the middle or the start of the window. For a rolling window drop the observation leaving the window; for an expanding window add the new one and keep the rest.
Worked example
- closes = [10, 12, 11, 13, 15, 14, 16]
- f = arithmetic mean
- w = 3 for the rolling case
- rolling values: 11, 12, 13, 14, 15
- expanding values: 10, 11, 11, 11.5, 12.2, 12.5, 13
- a centred 3-bar window stamped at bar 4 would average bars 3, 4 and 5 and therefore read bar 5
Interpretation
The output is a series of estimates, one per date, each valid only with the information available at that date. Comparing two window lengths compares two assumptions about memory, not two measurements of the same thing.
Assumptions
- The window ends at the date the estimate is stamped on, so no future observation enters.
- Window length is chosen before the strategy is evaluated, otherwise the choice is itself an optimised parameter.
- Observations inside the window are treated as drawn from one regime, which is the assumption the window length encodes.
- Consecutive rolling estimates overlap by w minus one observations, so they are heavily autocorrelated and their variability understates true uncertainty.
- A rolling window discards information abruptly at the trailing edge, which can produce a visible jump unrelated to any new data.
- An expanding window never adapts to a structural break, since the pre-break sample keeps its weight forever.
Related terminology
- related
- Lookahead Bias Moving Average Walk-Forward Testing In-Sample versus Out-of-Sample Standard Deviation Bollinger Bands Overfitting Backtesting Feature Leakage Autocorrelation
Moving Average
The window is the device; the moving average is one statistic computed inside it. A rolling standard deviation or rolling beta uses the same device.
Lookahead Bias
A centred or forward-shifted window is one of the commonest mechanical causes of lookahead bias, but the bias has many other sources.
Sources
McGraw-Hill · 2001 · chapters on rolling standard deviation and window selection
Print source
Editorial status
Flagged by the editor as uncertain on a linguistic, mathematical or regulatory point.
