backtesting_engine
Subject
Section titled “Subject”Sampling, Validation and ML Diagnostics
Why This Module Exists
Section titled “Why This Module Exists”AFML Chapters 11-12 require scenario-based validation with explicit anti-leakage controls, split provenance, and path-wise uncertainty rather than single-score reporting.
Mathematical Foundations
Section titled “Mathematical Foundations”CPCV Path Count
Section titled “CPCV Path Count”
Purge + Embargo Train Set
Section titled “Purge + Embargo Train Set”
Per-Path Sharpe
Section titled “Per-Path Sharpe”
Usage Examples
Section titled “Usage Examples”Run CPCV and inspect Sharpe distribution
Section titled “Run CPCV and inspect Sharpe distribution”use openquant::backtesting_engine::{ run_cpcv, BacktestData, BacktestRunConfig, BacktestSafeguards, CpcvConfig,};
let result = run_cpcv( &data, &BacktestRunConfig { mode_provenance: "research_v3_with_costs".to_string(), trials_count: 24, safeguards: BacktestSafeguards { survivorship_bias_control: "point-in-time universe".to_string(), look_ahead_control: "lagged features".to_string(), data_mining_control: "frozen split protocol".to_string(), cost_assumption: "spread + slippage".to_string(), multiple_testing_control: "trial count logged".to_string(), }, }, &CpcvConfig { n_groups: 8, test_groups: 2, pct_embargo: 0.01 }, |split| Ok(split.test_indices.iter().map(|i| pnl[*i]).collect()),)?;
println!("phi = {}", result.path_count);println!("path sharpe count = {}", result.path_distribution.len());API Reference
Section titled “API Reference”Rust API
Section titled “Rust API”run_walk_forwardrun_cross_validationrun_cpcvcpcv_path_countBacktestRunConfigBacktestSafeguardsWalkForwardConfigCrossValidationConfigCpcvConfig
Implementation Notes
Section titled “Implementation Notes”- Chapter 11: a backtest is a scenario sanity check; keep safeguards and assumptions attached to every run.
- Chapter 12: compare WF/CV/CPCV results by mode rather than averaging them into one statistic.
- CPCV output is a path distribution, enabling robust Sharpe diagnostics (e.g., quantiles) instead of point estimates.