Spaces:
Running
Running
File size: 2,055 Bytes
8e50444 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 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()
|