Spaces:
Sleeping
Sleeping
| import sys, os | |
| import warnings; warnings.filterwarnings('ignore') | |
| from backtesting.framework.config import STRATEGY_NAME, ACTIVE_STRATEGY_FN, ACTIVE_PARAMS, load_data | |
| try: | |
| from v30_causal_engine import evaluate_slice | |
| except ImportError: | |
| from backtesting.v30_causal_engine import evaluate_slice | |
| def run_test_2_1(): | |
| print("=" * 80) | |
| print(f" TEST 2.1: STRICT TRAIN/TEST SPLIT - {STRATEGY_NAME}") | |
| print("=" * 80) | |
| dc, spy, vf, daily_ret = load_data() | |
| print("Evaluating Full Strategy...") | |
| c = ACTIVE_STRATEGY_FN(dc, spy, vf, daily_ret, **ACTIVE_PARAMS) | |
| if isinstance(c, dict) and 'curve' in c: | |
| c = c['curve'] | |
| m_train = evaluate_slice(c, "2008-01-01", "2018-12-31") | |
| m_test = evaluate_slice(c, "2019-01-01", "2025-12-31") | |
| print(f" Train Sharpe (2008-2018): {m_train['sharpe']:.4f}") | |
| print(f" Test Sharpe (2019-2025): {m_test['sharpe']:.4f}") | |
| diff = m_test['sharpe'] - m_train['sharpe'] | |
| print(f" Difference (Out-of-Sample Lift): {diff:+.4f}") | |
| print("-" * 80) | |
| if diff > -0.20: | |
| if diff > 0: | |
| print(" VERDICT: STRONG PASS (Exceptionally robust, test improved)") | |
| else: | |
| print(" VERDICT: PASS (Test decay is within acceptable limits of -0.20)") | |
| else: | |
| print(" VERDICT: FAIL (Likely overfit, test decayed > -0.20)") | |
| if __name__ == "__main__": | |
| run_test_2_1() | |