Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix: Skip walk-forward folds where purging leaves no training data, as promised by the splitter contract.

Rudy Celeklib89c4e3836f7
diff --git a/README.md b/README.md
index b359b3ac8..02dd811eb 100644
--- a/README.md
+++ b/README.md
@@ -854,7 +854,7 @@ that is a bug, not a pattern.
| `attribution` | Brinson-Fachler decomposition |
| `performance` · `fundmath` | TWR / MWR / Modified Dietz; XIRR / MOIC / DPI / TVPI |
| `factormodel` · `eventstudy` | Factor regressions, event studies |
-| `multipletesting` · `crossvalidation` | Deflated significance, purged CV |
+| `multipletesting` · `crossvalidation` | Deflated significance, purged CV; purged walk-forward splits omit folds with no training observations left after purging. |
| `impact` | Market-impact models |
| `volatility` | Heston (1993) stochastic-volatility pricing |
| `portfolio` | Hierarchical Risk Parity allocation |
diff --git a/agent/src/quantlib/crossvalidation.py b/agent/src/quantlib/crossvalidation.py
index be2724f7b..e65b43e8b 100644
--- a/agent/src/quantlib/crossvalidation.py
+++ b/agent/src/quantlib/crossvalidation.py
@@ -476,6 +476,8 @@ def purged_walk_forward_splits(
# has already seen the test period.
reaches_in = label_ends[candidate] >= start
train = candidate[~reaches_in]
+ if train.size == 0:
+ continue
yield Split(
train=train,
test=np.arange(start, stop),
diff --git a/agent/tests/test_walkforward_empty_training_regressions.py b/agent/tests/test_walkforward_empty_training_regressions.py
new file mode 100644
index 000000000..33194b518
--- /dev/null
+++ b/agent/tests/test_walkforward_empty_training_regressions.py
@@ -0,0 +1,16 @@
+from src.quantlib.crossvalidation import (
+ purged_walk_forward_splits,
+ detect_boundary_leakage,
+)
+
+
+def test_walkforward_skips_fold_whose_training_labels_all_overlap():
+ ends = [3, 3, 3, 3, 7, 7, 7, 7]
+ splits = list(purged_walk_forward_splits(8, ends, n_folds=4))
+ assert [split.test.tolist() for split in splits] == [[4, 5], [6, 7]]
+ assert all(split.train.size for split in splits)
+ assert all(detect_boundary_leakage(split, ends).clean for split in splits)
+
+
+def test_walkforward_can_have_no_usable_folds():
+ assert list(purged_walk_forward_splits(8, [7] * 8, n_folds=4)) == []