Rolling and Expanding Windows for Time-Series Analysis
Summary
The article introduces rolling and expanding windows through stock-price examples. A rolling window calculates a statistic, such as a mean, over a fixed number of recent observations. As each new observation arrives, the window advances and older data drops out. The example applies a five-period moving average to a series of stock prices, illustrating how the estimate changes through time rather than relying on a single full-sample average.
An expanding window recalculates a statistic using all observations available so far, so its sample grows as new data arrives. The article shows an expanding mean alongside the full-sample mean to distinguish the evolving estimate from a statistic that uses the entire dataset. These approaches are useful for tracking changing conditions and building time-aware analyses. The examples are introductory and do not discuss choices such as window length, missing observations, or how to prevent look-ahead bias when using the resulting statistics in a backtest.
Key ideas
- A rolling window computes a statistic over a fixed span of recent observations.
- The rolling calculation advances through time and discards observations that leave the window.
- An expanding window includes all observations available up to each point, so its sample grows over time.
- Comparing either sequence with a full-sample statistic shows how estimates evolve through the dataset.
- The examples explain the mechanics but do not address window selection or backtest leakage.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.