Practice in Lab: Project: walk-forward forecasts with delayed labels and a purge gap →
Project: walk-forward forecasts with delayed labels and a purge gap
A random split cannot reproduce what an online forecaster knew at a historical decision time. Event timestamps and label-availability timestamps are different clocks. This backtest repeatedly fits an actual regression using only eligible history, applies an explicit gap and measures a future window. Delayed labels remain unavailable even when their event occurred long ago. Future targets may change reported error but cannot change an earlier forecast. Overlapping forecast windows are allowed and reported separately; treating their errors as independent would require additional justification.
rows = [{'event':1,'available':1}, {'event':2,'available':5}]
cutoff = 3
eligible = [r for r in rows if r['event']<=cutoff and r['available']<=cutoff]
print(eligible)Review the design
Review both clocks, the gap convention, overlapping windows and insufficient history. A production backtest also needs historical feature availability and immutable data snapshots.
Your task
Rows have unique id and finite t, available, x,y; available>=t. Cutoffs are finite, unique and strictly increasing; horizon>0 and gap>=0 are finite. At each cutoff, fit only rows with t<=cutoff-gap and label available<=cutoff. Forecast rows cutoff<t<=cutoff+horizon. Fit the centered one-feature ridge formula with penalty .1. Return one window with cutoff,status; evaluated windows also contain train_ids,held_ids,predictions,mse. Return status insufficient if fewer than two fitting rows or no held rows. Evaluation uses offline future truth; it must not enter fitting.
The explanation opens here once every check passes.