A test should recreate what you could have known when making a decision. A chronological split is a starting point; the information inside each row still needs inspection.
A concrete schedule
Use 240 ordered observations, an initial training window of 120, a five-row gap and a test window of 30. The numbers below are one-based row labels, with both endpoints included. They are a planning example, not market data.
| Fold | Expanding train | Excluded gap | Test |
|---|---|---|---|
| 1 | 1–120 | 121–125 | 126–155 |
| 2 | 1–150 | 151–155 | 156–185 |
| 3 | 1–180 | 181–185 | 186–215 |
The remaining rows, 216–240, cannot make a complete 30-row test window under this schedule and are left unused. In a rolling version, the second and third training ranges would be 31–150 and 61–180, preserving a 120-row training length.
Open the split planner and change these assumptions ↗
What belongs inside each fold?
Fit preprocessing and select parameters using the training data available for that fold. Apply the resulting transformation to its test data without refitting on that test. Scikit-learn’s data-leakage guide illustrates why fitting a transformation on all observations contaminates an evaluation.
If you choose parameters through validation, place that selection inside the training period. Repeatedly choosing the best system after inspecting every outer test turns those tests into another development set. Keep a separate final holdout when the research design calls for one, and document every occasion you inspect it.
A gap is measured in rows, not safety
A five-row gap is not automatically five days. Irregular timestamps, label horizons and publication delays need their own checks. For example, a training label based on the next ten bars may still reach into the test interval despite a five-row gap. Remove or shorten overlapping training labels according to their actual information intervals.
Previous test observations can enter a later training window once their required outcomes are available. That can reflect a real retraining process. It does not make the folds statistically independent.
External example: forecasting bicycle demand
The scikit-learn lagged-features example compares shuffled and time-ordered evaluation on bicycle-demand data. Use it to study the evaluation mistake. It is not a trading strategy, and forecast accuracy alone does not establish profitable execution.
Report the process, not just the average
Save each fold’s boundaries, chosen settings, data snapshot and result. Inspect variation across periods. If you combine test returns, define how positions, costs and capital carry across boundaries; do not silently reset a portfolio at every fold and present it as continuous trading.
Primary references
- scikit-learn: TimeSeriesSplit ↗
- scikit-learn: data leakage and preprocessing ↗
- scikit-learn: lagged features forecasting example ↗
References reviewed 28 October 2026. Original exercises and project-specific observations are identified separately.
Keep exploring
Build a validation split schedule ↗Educational engineering and research guidance. Examples do not establish a profitable or live-ready trading strategy.