harness(marginal): indurisci marginal_vs_tp01 con la lezione dell'onda ortho (17/18 -> 1)
Lo scorer fisso-HOLDOUT + jackknife-mese era ingannabile: 17/18 book relative-value "ADDS"
su una sola finestra 2025 (ETH-bleed dove TP01 è debole). Tre gate nuovi in
altlib.marginal_vs_tp01:
1. persistenza multi-cut (uplift a più date di taglio, non solo 2025) -> robust_oos
2. has_insample_edge: Sharpe standalone PRE-holdout >= 0.5 (la basket faceva 0.29).
null_pctl_* (vs asset-rumore corr-zero) restano come CONTESTO (diversification math).
3. is_hedge: low-corr che paga solo quando TP01 è debole = hedge, non alpha.
Verdetti nuovi HEDGE/NOISE; earns_slot = ADDS + robust_oos + has_insample_edge + not hedge.
Effetto: sull'onda ortho 17/18 "ADDS" -> 1 (dvol_spread, unico con edge in-sample reale 0.57);
gli altri 16 -> NOISE/HEDGE. Un sleeve sintetico Sharpe~1.3 scorrelato resta ADDS (non rigetta
i diversificatori veri). +5 test (noise/hedge/single-regime/high-Sharpe-uncorr/in-sample-edge);
suite 37 passed. CLAUDE.md aggiornato.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -47,3 +47,76 @@ def test_call_target_passes_asset_when_accepted():
|
||||
|
||||
al.candidate_daily(two_arg)
|
||||
assert seen == {"BTC": True, "ETH": True}
|
||||
|
||||
|
||||
# --- hardening gates (2026-06-21 ortho wave) -------------------------------------------
|
||||
# A low-corr asset adds ~+0.03 Sharpe by pure diversification MATH; a sleeve that only
|
||||
# pays when TP01 is weak is a HEDGE; an edge living in one late window is NOT robust.
|
||||
# These pin that the scorer rejects all three, but still PASSES a real high-Sharpe
|
||||
# uncorrelated sleeve (the diversification of a genuine return stream IS value).
|
||||
import pandas as pd # noqa: E402
|
||||
|
||||
|
||||
def _tp01_index():
|
||||
return al.tp01_baseline_daily().index
|
||||
|
||||
|
||||
def test_noise_sleeve_is_not_adds():
|
||||
"""Near-zero-Sharpe, zero-corr asset = diversification math, not signal -> not ADDS."""
|
||||
idx = _tp01_index()
|
||||
rng = np.random.default_rng(1)
|
||||
c = pd.Series(rng.normal(0.0001, 0.02, len(idx)), index=idx)
|
||||
m = al.marginal_vs_tp01(c)
|
||||
assert m["marginal_verdict"] != "ADDS"
|
||||
assert m["beats_noise_null"] is False
|
||||
|
||||
|
||||
def test_high_sharpe_uncorrelated_is_not_rejected_as_noise():
|
||||
"""A genuine Sharpe~1.3 uncorrelated sleeve (XS01-like) must NOT be called NOISE."""
|
||||
idx = _tp01_index()
|
||||
rng = np.random.default_rng(2)
|
||||
c = pd.Series(rng.normal(0.0011, 0.013, len(idx)), index=idx)
|
||||
m = al.marginal_vs_tp01(c)
|
||||
assert m["beats_noise_null"] is True
|
||||
assert m["marginal_verdict"] == "ADDS"
|
||||
|
||||
|
||||
def test_hedge_only_when_tp01_weak_is_flagged():
|
||||
"""A sleeve that pays only when TP01 trails down is a HEDGE, not alpha -> no slot."""
|
||||
B = al.tp01_baseline_daily()
|
||||
trail = B.rolling(60, min_periods=20).sum().shift(1)
|
||||
base = np.where(trail.values <= 0, 0.004, -0.001)
|
||||
rng = np.random.default_rng(4)
|
||||
c = pd.Series(base + rng.normal(0, 0.004, len(B)), index=B.index)
|
||||
m = al.marginal_vs_tp01(c)
|
||||
assert m["is_hedge"] is True
|
||||
assert m["marginal_verdict"] == "HEDGE"
|
||||
|
||||
|
||||
def test_flat_in_sample_late_edge_earns_no_slot():
|
||||
"""An edge FLAT in-sample that only appears in the recent window has NO standalone
|
||||
in-sample merit -> NOISE (not ADDS), no slot. This is the ortho 2025-window pattern."""
|
||||
B = al.tp01_baseline_daily()
|
||||
rng = np.random.default_rng(3)
|
||||
c = pd.Series(0.0, index=B.index) # exactly flat in-sample
|
||||
hold = B.index >= al.HOLDOUT
|
||||
c[hold] = 0.004 + rng.normal(0, 0.002, int(hold.sum())) # edge only in the hold-out
|
||||
m = al.marginal_vs_tp01(c)
|
||||
assert m["has_insample_edge"] is False
|
||||
assert m["marginal_verdict"] == "NOISE"
|
||||
assert al.marginal_vs_tp01(c)["marginal_verdict"] != "ADDS"
|
||||
|
||||
|
||||
def test_pre_holdout_underperformer_earns_no_slot():
|
||||
"""A sleeve with no real in-sample standalone edge (it bleeds before the hold-out and
|
||||
only wins in the recent window) never earns a slot — the 2025-only ortho pattern."""
|
||||
B = al.tp01_baseline_daily()
|
||||
early = B.index < al.HOLDOUT
|
||||
rng = np.random.default_rng(5)
|
||||
c = pd.Series(0.0, index=B.index)
|
||||
c[early] = -0.0008 + rng.normal(0, 0.012, int(early.sum())) # weak/negative in-sample
|
||||
c[~early] = 0.010 + rng.normal(0, 0.012, int((~early).sum())) # strong only post-hold-out
|
||||
m = al.marginal_vs_tp01(c)
|
||||
assert m["cand_insample_sharpe"] < 0.5
|
||||
assert m["has_insample_edge"] is False
|
||||
assert m["marginal_verdict"] != "ADDS"
|
||||
|
||||
Reference in New Issue
Block a user