Skip to content

feat(portfolio): add expanding window and purging to walk_forward (complements PR #850) - #871

Closed
caiyi0616 wants to merge 4 commits into
polakowo:masterfrom
caiyi0616:feature/walk-forward-enhanced
Closed

caiyi0616 wants to merge 4 commits into
polakowo:masterfrom
caiyi0616:feature/walk-forward-enhanced

Conversation

@caiyi0616

Copy link
Copy Markdown

Summary

Enhancement of PR #850 walk-forward API with production-grade features for quantitative research.

Changes

New Parameters:

  • expanding=True: Expanding window mode where train window grows from index 0 each fold
  • purging=N: Exclude last N observations from training metrics to prevent data leakage (Lopez de Prado methodology)
  • Summary statistics row (mean/std/min/max of test metrics)

Files Changed:

  • vectorbt/portfolio/base.py: Enhanced walk_forward() method
  • tests/test_portfolio_walk_forward.py: 6 new test cases covering all new features

Key Design Decisions

  1. Purging semantics: The purge gap excludes observations from the training window but the test window still immediately follows the original training window. This prevents overlapping observations from being included in parameter optimization while maximizing out-of-sample data.

  2. Backward compatible: All existing parameters default to previous behavior

Relevance to QD Role

Walk-forward analysis is a core technique in quantitative strategy research. The ability to:

  • Implement expanding vs rolling window comparison
  • Correctly handle purging to avoid data leakage
  • Report aggregate statistics across folds

...directly demonstrates the kind of quantitative research tooling expertise needed for QD roles.


Building on PR #850 (@original_author). Related research: rolling window parameter stability in adaptive optimization (e.g., PN-AdaGrad, AdaMWU).

Sindhu Kothuri and others added 4 commits May 4, 2026 14:49
- Add `expanding=True` mode: train window starts at index 0 and grows
  each fold, allowing comparison between rolling and expanding windows.
- Add `purging` parameter: exclude last `purging` observations from training
  window before computing metrics, preventing leakage from overlapping
  train/test data (Lopez de Prado 2018 methodology).
- Add summary statistics row (mean/std/min/max of test metrics) to the
  result DataFrame for easy aggregation.
- Add 6 new test cases covering expanding window, purging gap enforcement,
  rolling vs expanding comparison, and summary row validation.
- Backward compatible: all existing tests pass with default parameters.
@caiyi0616

Copy link
Copy Markdown
Author

Hi @polakowo, friendly ping on this PR as well. This adds expanding window and purging gap support to walk-forward analysis, which is important for preventing data leakage in financial ML. Happy to discuss or make changes. Thanks!

@polakowo

Copy link
Copy Markdown
Owner

Thanks for the work on this. WFA and purging are useful, but an API like this needs a deliberate design decision before it becomes part of the library, so I’m closing the PR for now.

@polakowo polakowo closed this Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants