Quant Memo
Foundational

Sliding-Window Supervision for Time Series

Turning one long time series into a supervised learning dataset means repeatedly cutting out a fixed-length window as the input and the next value as the label, sliding forward one step at a time.

Prerequisites: The Multilayer Perceptron

Ordinary supervised learning needs a table of independent rows, each with its own inputs and a label. A time series is just one long sequence of numbers with no such rows to begin with — so how do you turn a single scroll of daily prices into anything a standard model, or even a neural network, can train on?

The analogy: flashcards from a scroll

Imagine unrolling a long scroll of text and making flashcards: each card shows the last few lines as the "question" and the very next line as the "answer," then you slide one line down the scroll and make the next card. A sliding window does exactly this to a time series — cut out a fixed-length window ending at time tt as the input, pair it with the value at t+ht+h (some steps ahead) as the target, then slide forward by one step and repeat.

The mechanics

Given a series x1,,xTx_1, \dots, x_T, a window length LL, and a forecast horizon hh, each training example is:

Xt=(xtL+1,,xt),yt=xt+hX_t = (x_{t-L+1}, \dots, x_t), \qquad y_t = x_{t+h}

In words: the input is the last LL observed values ending at time tt; the label is the value hh steps into the future from that same point. Sliding tt forward one step at a time (or by some larger stride) across the whole series produces many overlapping training pairs from a single sequence.

Worked example 1: building the pairs

An 8-day price series: 10,11,13,12,14,15,14,1610, 11, 13, 12, 14, 15, 14, 16. With window L=3L=3, horizon h=1h=1, stride 11: pair 1 uses X=(10,11,13)X=(10,11,13), y=12y=12; pair 2 uses X=(11,13,12)X=(11,13,12), y=14y=14; pair 3 uses X=(13,12,14)X=(13,12,14), y=15y=15; pair 4 uses X=(12,14,15)X=(12,14,15), y=14y=14; pair 5 uses X=(14,15,14)X=(14,15,14), y=16y=16. Five overlapping training examples from one 8-value series.

Worked example 2: increasing the stride

Same series, same L=3L=3, h=1h=1, but stride 22: pair 1 uses X=(10,11,13)X=(10,11,13), y=12y=12 (starting at t=3t=3); pair 2 uses X=(13,12,14)X=(13,12,14), y=15y=15 (starting at t=5t=5, two steps later). Only 2 pairs instead of 5 — fewer, but far less overlapping, since each new window shares less data with the previous one. Larger stride trades training-set size for less redundant, more independent-looking examples.

window (input) target
A fixed-length window of past values (dashed box) is the input; the very next point (highlighted) is the label. Sliding the window one step produces the next overlapping training pair.
stride 1 (5 overlapping windows) stride 2 (2 windows, little overlap)
A stride of 1 packs many highly-overlapping windows from one series; a larger stride trades fewer, less redundant examples for a smaller effective dataset.

Sliding-window supervision converts one time series into many training pairs by cutting fixed-length input windows and pairing each with a future target, but because adjacent windows share nearly all their data, the resulting examples are heavily autocorrelated, not independent.

What this means in practice

This is literally how raw price or return history becomes a training set for a return-prediction model. Window length LL is a real hyperparameter: too short and the model lacks context; too long and old, possibly stale information dilutes recent signal. Because of the overlap, a train/test split must respect time order — never shuffle windows randomly the way you would independent tabular rows — and typically needs a gap ("embargo") between the end of the training windows and the start of the test windows.

Randomly shuffling sliding-window samples into train and test sets, as you would with i.i.d. tabular data, leaks information: a test window that overlaps a training window by even one timestep is not a genuinely independent test, because the model has effectively already seen most of that data during training. This single mistake is one of the most common ways a backtest looks far better than live performance will actually be.

Related concepts

Practice in interviews

Further reading

  • Hyndman & Athanasopoulos, Forecasting: Principles and Practice (2021)
ShareTwitterLinkedIn