harness(causality): guardia look-ahead + calendar-artifact self-policing nel lab intraday
- altlib.causality_ok(target_fn, tf): online-consistency guard (ricalcola il target su un prefisso, la coda deve combaciare col full). eval_weights shifta la posizione ma non vede una feature non-causale (finestra centrata/shift(-k)/stat full-sample) -> questa sì. - intra_score integra DUE gate prima/dopo lo scoring: causality (leak -> LEAK, squalificato) e day_boundary_robust (ARTIFACT-RISK -> fuori dagli slot). Effetto sul leaderboard intraday: open_drive + weekly_seasonality + overnight -> CAL-ARTIFACT (da soli, niente skeptic); prevday_range_breakout resta (ROBUST). earns_slot 10 -> 8. - +2 test (causal-ok / leak), suite intera verde. Il lab intraday ora auto-becca leak e artefatti-calendario che ieri richiedevano 3 scettici. Chiude la 3a lezione harness dell'onda intraday. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -60,3 +60,24 @@ def test_smallcap_keeps_real_trades():
|
||||
r = al.eval_weights_smallcap(df, step, capital=600.0, min_order=5.0)
|
||||
assert r["n_executed_trades"] >= 2
|
||||
assert abs(r["sharpe_haircut"]) < 0.2
|
||||
|
||||
|
||||
# --- LESSON 3: look-ahead (online-consistency) guard -----------------------------------
|
||||
def test_causality_passes_causal_signal():
|
||||
"""A causal signal recomputed on a prefix matches the full run on its tail."""
|
||||
def mom(df):
|
||||
c = df["close"].values
|
||||
return np.tanh(3 * (c / al.sma(c, 200) - 1))
|
||||
r = al.causality_ok(mom, tf="1h")
|
||||
assert r["ok"] is True
|
||||
assert r["max_tail_diff"] == 0.0
|
||||
|
||||
|
||||
def test_causality_flags_lookahead():
|
||||
"""A signal that reads tomorrow's move (future peek) is disqualified."""
|
||||
def leaky(df):
|
||||
c = df["close"].values
|
||||
f = np.zeros(len(c)); f[:-1] = np.sign(c[1:] - c[:-1]) # uses close[i+1]
|
||||
return f
|
||||
r = al.causality_ok(leaky, tf="1h")
|
||||
assert r["ok"] is False
|
||||
|
||||
Reference in New Issue
Block a user