Basic Prerequisites: 01 · From Zero.
1. Intuition & Practical Objective
Standard -fold CV was built for IID data: each row is an independent draw, so no row in the training set can tell you anything about a row in the test set except what the model should generalise. Finance violates the premise twice, and the second violation is what this page makes visible:
- The data are not IID. Features are serially correlated () and labels are formed on overlapping windows (). Putting a training row next to a test row that is its near-duplicate leaks the answer.
- The test set is reused. The same test data is consulted again and again while a researcher searches hyperparameters, features, and model families - selection bias, the second way CV overstates skill (AFML §7.3). That second cause is the domain of Backtesting Hygiene.
The objective of this page is to demonstrate cause #1 so concretely that you never trust an un-purged financial CV score again: on a pure-noise target, standard CV’s accuracy rises toward the adjacent-label agreement simply because you make the folds thinner. That is not signal. That is leakage.
2. Mathematical Ground Truth & Derivations
The two ingredients of label leakage. A classifier trained on is asked to predict from . It scores correctly even when is irrelevant when both near-equalities hold:
López de Prado (AFML §7.3) is explicit: leakage requires the pair . alone, or alone, is not enough - the model must be able to map a near-duplicate feature to a near-duplicate label.
Why thin folds leak more. In contiguous -fold CV, each fold is a block of bars. An observation inside a thick block has its temporal neighbours in the same test block, so no training row is a near-duplicate - leakage is confined to the two fold boundaries. As the blocks shrink (larger , toward leave-one-out), a larger fraction of test rows sit next to a training row, so the leaked fraction grows. AFML §7.4.1 states the diagnostic directly: “When leakage takes place, performance improves merely by increasing .” The purge-free CV then reports accuracy that is a function of how many folds you chose, not of any real skill.
3. Computational Implementation - manufacturing a false discovery
Stdlib only. Target is pure noise (iid daily returns - there is no edge by construction). The “learner” copies the nearest training label in time - the minimal model that exploits serial structure. It must score under honest evaluation; under standard CV it “learns” exactly as much as the folds leak.
Read the columns. Under standard contiguous -fold the accuracy is not constant - it climbs from (thick folds) to (leave-one-out), converging exactly on the adjacent-label agreement : the classifier is “earning” nothing but leaked duplicates. Under purging, every configuration sits at regardless of fold count - the honest null, because the leaked training rows have been deleted. This is the textbook false discovery, manufactured end-to-end from noise, exactly as AFML §7.3 predicts.
4. Failure Modes & First-Principles Breakdowns
- Choosing folds to flatter yourself. If un-purged CV accuracy rises with , that is the leak diagnostic (AFML §7.4.1). Reporting “best-” accuracy without purging is reporting your choice of folds.
- Shuffling hides the crime. Shuffled CV interleaves near-duplicate pairs across every fold, so even thick folds leak - and the score goes up (AFML Ex. 7.2). Shuffling is not a cure; it is how the leak becomes total.
- Crossing into the second failure. Even a correctly purged CV suffers selection bias if the test set is reused across many trials. Purged CV fixes label leakage, not the missing- problem - that is the separate domain of Backtesting Hygiene (DSR, PBO).
5. References
- López de Prado, Advances in Financial Machine Learning, Ch. 7 (§7.3 “Why k-fold CV fails in finance”;
- Hastie, Tibshirani & Friedman, The Elements of Statistical Learning, Ch. 7 (§7.10.2 wrong-vs-right CV; the full-data-screening example reports 3% CV error against a true 50%)
6. Connected Graph Bridges
- Back: 01 · From Zero · Index Hub
- Forward: 03 · Purging & Embargo
- The second failure (selection bias): Backtesting Hygiene