import sys, os import numpy as np import warnings; warnings.filterwarnings('ignore') from backtesting.framework.config import STRATEGY_NAME, ACTIVE_STRATEGY_FN, ACTIVE_PARAMS, REBAL_PARAM_NAME, load_data try: from backtesting.engines.v30_causal_engine import evaluate_slice except ImportError: from backtesting.engines.v30_causal_engine import evaluate_slice def run_test_2_2(): print("=" * 80) print(f" TEST 2.2: START DATE SENSITIVITY - {STRATEGY_NAME}") print("=" * 80) dc, spy, vf, daily_ret = load_data() rebal = ACTIVE_PARAMS.get(REBAL_PARAM_NAME, 60) # Ensure strictly ~20 offsets step = max(1, rebal // 20) offsets = list(range(0, rebal, step))[:20] print(f"Running {len(offsets)} start date offsets to sample path dependency...") sharpes = [] cagrs = [] mdds = [] for off in offsets: c_off = ACTIVE_STRATEGY_FN(dc.iloc[off:], spy.iloc[off:], vf, daily_ret.iloc[off:], **ACTIVE_PARAMS) if isinstance(c_off, dict) and 'curve' in c_off: c_off = c_off['curve'] m = evaluate_slice(c_off, "2008-01-01", "2025-12-31") sharpes.append(m['sharpe']) cagrs.append(m['cagr']) mdds.append(m['mdd']) print(".", end="", flush=True) print() s_mean = np.mean(sharpes) s_max = np.max(sharpes) s_min = np.min(sharpes) s_range = s_max - s_min c_mean = np.mean(cagrs) d_mean = np.mean(mdds) print(f" Mean Sharpe: {s_mean:.4f}") print(f" Mean CAGR: {c_mean:.1f}%") print(f" Mean MaxDD: {d_mean:.1f}%") print(f" Min Sharpe: {s_min:.4f}") print(f" Max Sharpe: {s_max:.4f}") print(f" Range: {s_range:.4f}") print("-" * 80) if s_range < 0.20: print(" VERDICT: PASS (Low path dependency, structurally robust)") else: print(" VERDICT: FAIL (High path dependency, unreliable variance)") if __name__ == "__main__": run_test_2_2()