"""Locks the marginal-vs-TP01 scorer (altlib) — the harness fix from the 2026-06-20 sweep. The point: absolute Sharpe is not enough to earn a portfolio slot. A candidate must IMPROVE the TP01 baseline out-of-sample. These tests pin the invariants: * the TP01 baseline reproduces the canonical ~1.30 full Sharpe, * TP01-vs-itself is REDUNDANT (zero marginal), * a flat (do-nothing) sleeve never earns a slot. """ import sys from pathlib import Path import numpy as np ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "scripts" / "research" / "alt")) import altlib as al # noqa: E402 from src.strategies.trend_portfolio import CANONICAL, TrendPortfolio # noqa: E402 def test_tp01_baseline_reproduces_canonical(): r = al.tp01_baseline_daily().values sharpe = float(np.mean(r) / np.std(r) * np.sqrt(365.25)) assert 1.1 < sharpe < 1.5, f"TP01 baseline Sharpe {sharpe:.2f} off canonical ~1.30" def test_tp01_vs_itself_is_redundant(): cand = al.candidate_daily(lambda df: TrendPortfolio(**CANONICAL).target_series(df)) m = al.marginal_vs_tp01(cand) assert m["corr_full"] > 0.95 assert abs(m["blends"]["w25"]["uplift_full"]) < 0.05 assert m["marginal_verdict"] == "REDUNDANT" assert al.study_marginal("tp01-self", lambda df: TrendPortfolio(**CANONICAL).target_series(df))["earns_slot"] is False def test_flat_sleeve_earns_no_slot(): m = al.marginal_vs_tp01(al.candidate_daily(lambda df: np.zeros(len(df)))) assert m["marginal_verdict"] != "ADDS" def test_call_target_passes_asset_when_accepted(): seen = {} def two_arg(df, asset): seen[asset] = True return np.zeros(len(df)) al.candidate_daily(two_arg) assert seen == {"BTC": True, "ETH": True}