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 as the input, pair it with the value at (some steps ahead) as the target, then slide forward by one step and repeat.
The mechanics
Given a series , a window length , and a forecast horizon , each training example is:
In words: the input is the last observed values ending at time ; the label is the value steps into the future from that same point. Sliding 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: . With window , horizon , stride : pair 1 uses , ; pair 2 uses , ; pair 3 uses , ; pair 4 uses , ; pair 5 uses , . Five overlapping training examples from one 8-value series.
Worked example 2: increasing the stride
Same series, same , , but stride : pair 1 uses , (starting at ); pair 2 uses , (starting at , 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.
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 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)