Unit 13, lesson 100

Time series validation and overlapping labels

How chronological splits and walk-forward validation follow the forecast timeline, when overlapping labels share increments, how purging and an embargo remove them, and how nested validation keeps tuning apart from evaluation.

  • Video 100
  • Validation, multiple testing and cointegration

A model forecasts the three-day return of an equity index from daily data, and the question is how accurate its forecasts would have been in the past. A random split of the rows into training and validation sets is quick, but a training row dated before a forecast can carry a return that finishes after it, and neighboring three-day returns share two of their three daily returns. This lesson states exactly which rows a historical forecast could have trained on, which rows share outcomes with the validation rows and must be purged, what an embargo adds, and how nested validation keeps the choice of tuning parameters apart from the score that judges it.

Key terms

Chronological split

Definition Time is counted in integer observation intervals, and increment kk is the change observed at time kk, for example the log return rkr_k from time k−1k - 1 to time kk. A label with horizon h≥1h \ge 1 that starts at time tt is a function of the increments in its information interval

It={t+1,…,t+h},\mathcal{I}_t = \{t + 1, \dots, t + h\},

for example the hh-period log return yt=rt+1+⋯+rt+hy_t = r_{t+1} + \dots + r_{t+h}, and the features xtx_t of the row use only information available at time tt. The label is complete at time t+ht + h. Take the convention that a decision at time TT is made after increment TT has been observed. A chronological split at decision time TT trains only on rows whose labels are complete at TT and evaluates only forecasts made at TT or later,

t+h≤T(training),t≥T(validation).\begin{gathered} t + h \le T \quad (\text{training}), \\[0.4em] t \ge T \quad (\text{validation}). \end{gathered}

Starts with T−h<t<TT - h < t < T belong to neither set at that decision, because their features are known but their labels are not. If the decision is made before increment TT is observed, the training condition becomes t+h≤T−1t + h \le T - 1. A random split assigns rows to training and validation without regard to these times, so in general it trains on outcomes that were not known when the validation forecasts were made.

In plain words The date of a row is when its forecast would have been made, not when its outcome became known. A row can train a model at a decision only if its whole outcome had already arrived.

Example Take h=3h = 3 and a decision at T=6T = 6. The starts 00 to 33 have labels complete by time 66, since 3+3=63 + 3 = 6, so they are the training rows. Start 55 is dated before the decision, but its label uses increments 66, 77 and 88, and the last two have not happened at time 66. For a one-period label, h=1h = 1, at the same decision the training starts are 00 to 55, so changing the horizon changes the training sample.

Walk-forward validation

Definition Walk-forward validation repeats the chronological split at increasing decision times T1<T2<⋯<TJT_1 < T_2 < \dots < T_J. At decision TjT_j the model, together with every preprocessing step that learns from data, is fitted on rows with t+h≤Tjt + h \le T_j, either all of them (an expanding window) or only the latest WW of them (a rolling window). The fitted predictor f^j\hat f_j then forecasts the starts of the block Bj={Tj,…,Tj+1−1}B_j = \{T_j, \dots, T_{j+1} - 1\}, where TJ+1T_{J+1} marks the end of the sample, and each forecast is scored with a loss ℓ\ell once its label is complete. With nn forecasts in all, the walk-forward score is

R^WF=1n∑j=1J∑t∈Bjℓ(f^j(xt),yt).\begin{aligned} &\widehat{R}_{\mathrm{WF}} \\[0.4em] &= \frac{1}{n}\sum_{j=1}^{J}\sum_{t \in B_j}\ell\bigl(\hat f_j(x_t), y_t\bigr). \end{aligned}

Every forecast uses only information available when it is made, because its training labels end by Tj≤tT_j \le t and its features are known at tt. The score is therefore the historical loss of the procedure run the way it would have been run. It estimates future loss only under further assumptions on the stability and dependence of the losses, which the chronological order does not supply.

In plain words Stand at each historical decision date in turn, fit with what was known then, forecast the next block, and move forward. A row trains a forecast only if its outcome was already known when that forecast was made.

Example In a constructed timeline with h=3h = 3 and validation starts 66, 77 and 88, refitting at every start gives the training starts 00 to 33 at decision 66, 00 to 44 at decision 77 and 00 to 55 at decision 88. A single fit at decision 66, used for all three forecasts, trains on the starts 00 to 33 only. No start after the validation block ever trains one of these forecasts, however far its label lies from the validation labels.

Overlapping labels

Definition Two labels overlap when their information intervals share an increment, Is∩It≠∅\mathcal{I}_s \cap \mathcal{I}_t \ne \varnothing. For two labels with the same horizon hh this happens exactly when ∣t−s∣<h\lvert t - s \rvert < h, and they then share h−∣t−s∣h - \lvert t - s \rvert increments. Suppose in addition that each label is the sum of its increments and that the increments are uncorrelated with a common variance σ2\sigma^2. Then

Cov⁡(ys,yt)=σ2(h−∣t−s∣)+,\begin{aligned} &\operatorname{Cov}(y_s, y_t) \\[0.4em] &= \sigma^2 \bigl(h - \lvert t - s \rvert\bigr)^{+}, \end{aligned}

so the correlation of the two labels is (1−∣t−s∣/h)+(1 - \lvert t - s \rvert / h)^{+}. For the mean yˉ\bar y of the nn consecutive labels starting at 1,…,n1, \dots, n,

Var⁡(yˉ)=σ2n2∑s=1n∑t=1n(h−∣t−s∣)+,\begin{aligned} &\operatorname{Var}(\bar y) \\[0.4em] &= \frac{\sigma^2}{n^2}\sum_{s=1}^{n}\sum_{t=1}^{n}\bigl(h - \lvert t - s \rvert\bigr)^{+}, \end{aligned}

and nVar⁡(yˉ)n \operatorname{Var}(\bar y) tends to σ2h2\sigma^2 h^2 as nn grows, because the weights h−∣k∣h - \lvert k \rvert over the lags ∣k∣<h\lvert k \rvert < h add up to h2h^2. The formula Var⁡(yt)/n=σ2h/n\operatorname{Var}(y_t)/n = \sigma^2 h/n for independent observations therefore understates this variance by a factor that approaches hh.

In plain words Neighboring three-day returns are built mostly from the same days. Putting one of them in training and its neighbor in validation does not give two separate pieces of evidence, and treating overlapping rows as independent observations overstates how much the data say.

Example With h=3h = 3, the labels starting at 44 and 55 use the increments 55, 66, 77 and 66, 77, 88, so they share 66 and 77, and with uncorrelated increments of equal variance their correlation is 2/32/3. The labels starting at 44 and 77 share no increment. For n=300n = 300 consecutive three-period labels with σ2=1\sigma^2 = 1, the exact variance of the mean is 673/22500≈0.0299673/22500 \approx 0.0299, about 2.992.99 times the value 3/300=0.013/300 = 0.01 that the independence formula gives.

Purging

Definition Let SS be the set of validation starts and

V=⋃t∈SItV = \bigcup_{t \in S} \mathcal{I}_t

the union of their information intervals. Purging removes from the training candidates every start t∉St \notin S whose interval meets VV, so that every retained training label satisfies It∩V=∅\mathcal{I}_t \cap V = \varnothing. For a contiguous validation block S={a,…,b}S = \{a, \dots, b\} and a common horizon hh, the union is V={a+1,…,b+h}V = \{a + 1, \dots, b + h\}, and a start outside the block is retained exactly when t+h≤at + h \le a or t≥b+ht \ge b + h. This removes the h−1h - 1 starts a−h+1,…,a−1a - h + 1, \dots, a - 1 before the block and the h−1h - 1 starts b+1,…,b+h−1b + 1, \dots, b + h - 1 after it, whenever they exist. In continuous event time the same test compares intervals such as (t,t+h](t, t + h], and the endpoint convention must be stated, since an observation exactly on a boundary may or may not be shared. Purging removes only the specified overlap of label intervals. It does not make the retained rows independent of the validation rows, which can still depend on them through persistent volatility, slowly moving features or a common market regime.

In plain words Shade every increment that some validation label uses, then drop every training label that touches a shaded increment. The test is a set intersection, not a rule of thumb about how many rows to skip.

Example In a constructed timeline with candidate starts 00 to 1515, horizon h=3h = 3 and validation starts 66, 77 and 88, the validation intervals {7,8,9}\{7, 8, 9\}, {8,9,10}\{8, 9, 10\} and {9,10,11}\{9, 10, 11\} give V={7,…,11}V = \{7, \dots, 11\}, each increment counted once. Start 44 uses 55, 66, 77 and meets VV at 77, and start 55 meets it at 77 and 88. Start 99 uses 1010, 1111, 1212 and start 1010 uses 1111, 1212, 1313. Purging removes 44, 55, 99 and 1010, and the label-disjoint training starts are 00 to 33 and 1111 to 1515. Label-disjoint is not the same as available. The starts 1111 to 1515 pass the overlap test, yet none of their labels is complete at time 66. With the decision at the first validation start, T=aT = a, the walk-forward condition t+h≤Tt + h \le T is exactly the left half of the purging rule.

Embargo

Definition An embargo is an additional exclusion of training starts in a stated window after a validation block, applied on top of purging. Its width follows from the design, for example from the feature windows, and no single width removes all dependence. Suppose the features of start tt use the L≥1L \ge 1 most recent increments t−L+1,…,tt - L + 1, \dots, t. Among the starts after the block that survive purging, those with t≥b+ht \ge b + h, the feature window meets V={a+1,…,b+h}V = \{a + 1, \dots, b + h\} exactly when t−L+1≤b+ht - L + 1 \le b + h. Excluding them removes the LL starts b+h,…,b+h+L−1b + h, \dots, b + h + L - 1, whose inputs were built partly from the validation outcomes. An embargo matters only in blocked designs that train on rows after the validation block. Walk-forward validation never does.

In plain words Purging handles shared outcomes. An embargo handles a second channel, later rows whose inputs were computed from the validation period. It is a rule you choose and justify from your own windows, not a fixed number of days.

Example Continue the constructed timeline with features built from the three most recent increments, L=3L = 3. Start 1111 uses 99, 1010, 1111, start 1212 uses 1010, 1111, 1212 and start 1313 uses 1111, 1212, 1313, so all three meet VV, while start 1414 uses 1212, 1313, 1414. The embargo removes 1111, 1212 and 1313, and the blocked design keeps the starts 00, 11, 22, 33, 1414 and 1515. That set belongs to this blocked design with this embargo. It still contains the starts 1414 and 1515, which cannot train a forecast made at time 66.

Nested validation

Definition Nested chronological validation uses two layers of splits. Outer fold j=1,…,Jj = 1, \dots, J has an outer training window DjD_j, whose labels are complete at the outer decision TjT_j, and a later outer block BjB_j. Each candidate tuning parameter λ\lambda, for example a ridge penalty, is scored by chronological, purged inner splits that use only rows of DjD_j, and the inner winner is

λ^j=argmin⁡λ R^inner,j(λ).\hat\lambda_j = \operatorname{argmin}_{\lambda}\,\widehat{R}_{\mathrm{inner},j}(\lambda).

The procedure is refitted on DjD_j with λ^j\hat\lambda_j and scored once on BjB_j, and the outer estimate is

R^outer=1J∑j=1JR^future,j(λ^j).\widehat{R}_{\mathrm{outer}} = \frac{1}{J}\sum_{j=1}^{J}\widehat{R}_{\mathrm{future},j}(\hat\lambda_j).

Every step that learns from data, including imputation, normalization, feature selection and probability calibration, is fitted inside the same windows. The outer estimate scores the whole procedure, tuning included, rather than one fixed model. The minimized inner score is not an assessment of the selected model, because it took part in the choice. Equal fold weights 1/J1/J and weights proportional to the number of predictions in each block give different averages when the blocks differ in size, so a report states which expected loss it estimates. If several procedures are then compared by their outer scores and the best is kept, those scores have become selection information as well, and assessing the kept procedure takes a later block that played no part in any choice.

In plain words Use the past to choose and the future to judge. A score that helped make a choice can no longer judge that choice, whatever the dataset holding it is called.

Example Take constructed monthly labels with h=1h = 1. Outer fold 11 has D1D_1 equal to the starts 00 to 5959, complete at T1=60T_1 = 60, and B1B_1 equal to the starts 6060 to 7171. Inside D1D_1, each penalty is fitted on the starts 00 to 3535 and scored on 3636 to 4747, then fitted on 00 to 4747 and scored on 4848 to 5959. The penalty with the lower average inner score is refitted on 00 to 5959 and scored once on 6060 to 7171. Outer fold 22 repeats this with D2D_2 equal to 00 to 7171 and B2B_2 equal to 7272 to 8383. The months 6060 to 7171 never influence the choice that fold 11 makes.

Check yourself

  1. Labels have horizon h=4h = 4, the candidate starts are 00 to 2020 and the validation starts are 1010, 1111 and 1212. Find the validation union VV, the purged starts and the label-disjoint training starts.
Show the answer

The validation intervals are {11,…,14}\{11, \dots, 14\}, {12,…,15}\{12, \dots, 15\} and {13,…,16}\{13, \dots, 16\}, so V={11,…,16}V = \{11, \dots, 16\}. A start outside the block is label-disjoint exactly when t+4≤10t + 4 \le 10 or t≥16t \ge 16, that is, t≤6t \le 6 or t≥16t \ge 16. The purged starts are 77, 88, 99 and 1313, 1414, 1515, three on each side since h−1=3h - 1 = 3. For instance, start 99 uses 1010 to 1313 and meets VV at 1111, 1212 and 1313, while start 66 uses 77 to 1010 and misses it. The label-disjoint training starts are 00 to 66 and 1616 to 2020.

  1. In the setting of the first question, the first validation forecast is made at time 1010. A colleague trains it on all label-disjoint starts. Which starts are admissible, and how does the answer change if the forecast must be issued before increment 1010 is observed, or if the horizon is h=1h = 1 instead?
Show the answer

Under the convention that the decision at time 1010 follows increment 1010, a training label must satisfy t+4≤10t + 4 \le 10, so the admissible starts are 00 to 66. The starts 1616 to 2020 are label-disjoint but their labels end at times 2020 to 2424, long after the forecast, so the colleague’s sample uses outcomes that did not exist yet. If the forecast is issued before increment 1010 is observed, the condition becomes t+4≤9t + 4 \le 9 and only the starts 00 to 55 remain. With h=1h = 1 and the original convention, the condition t+1≤10t + 1 \le 10 admits the starts 00 to 99.

  1. Three outer blocks of a nested walk-forward design hold 5050, 5050 and 100100 predictions with average squared losses 0.80.8, 1.01.0 and 1.41.4, in constructed units. Compute the equal-fold average and the prediction-weighted average. The analyst then tries ten penalty grids, keeps the grid with the best outer score and reports that score as its expected loss. What is wrong with the report?
Show the answer

The equal-fold average is

0.8+1.0+1.43=3.23≈1.067.\begin{aligned} &\frac{0.8 + 1.0 + 1.4}{3} \\[0.4em] &= \frac{3.2}{3} \approx 1.067 . \end{aligned}

The prediction-weighted average divides the total loss 50⋅0.8+50⋅1.0+100⋅1.4=23050 \cdot 0.8 + 50 \cdot 1.0 + 100 \cdot 1.4 = 230 by the 200200 predictions, which gives 1.151.15. The two differ because the third block is larger and has higher losses. The first weights each fold equally, the second each prediction, and the report should say which one it estimates. Once ten grids are compared by their outer scores and the best is kept, the outer blocks have taken part in a selection, so the winning score is no longer an untouched assessment and tends to be optimistic. An honest assessment of the kept grid needs a later block that informed no choice. A standard error for either average also needs a model of the dependence between losses, since adjacent forecasts with overlapping labels are not independent.

How this lesson connects