research(xsec): sweep cross-sectional su Hyperliquid (43 script/257 config) + verifica avversariale
Nuova harness condivisa xslib.py (panel HL certificato, score per-asset causale, book long-k/short-k vol-targeted leak-free) + 43 script in runs/ su 11 famiglie (MOM/REV/VOL/ DIST/LIQ/VAL/STRUCT/UNIV). Scoring = earns_slot (full>0 AND hold-out>0 AND marginal ADDS al portafoglio live AND corr XS01<0.6, con jackknife drop-one-month). Find: 42/257 config earns_slot=True, ma TUTTE con corr TP01 -0.2..-0.4 e PnL ~solo 2025. Verify (verify_survivors.py, 3 scettici deterministici): - S1 redundancy: cluster low-vol = UNA scommessa (XV01=XU02=1.00, XV02/XV03 r 0.44-0.67); XM09/XL02/XS06b/XR02 distinti (corr media off-diag +0.20). - S2 short-beta: cluster low-vol carica 0.44-0.70 su short-market -> NON market-neutral, e' un tilt short-alt-beta di regime. XM09(0.08)/XR02(-0.21) NON short-beta. - S3 per-anno: cluster low-vol decade (XV01/XU02 2026 -0.09); XL02 morto (2025 -0.14, 2026 -0.43); XM09 (0.82/0.50/0.74) e XR02 (0.84/0.40/2.68) positivi in tutti e 3 gli anni. Esito: nessuna sleeve nuova. Cluster low-vol RIGETTATO (regime-bet), XL02 RIGETTATO (overfit). 2 LEAD genuini (XM09 trend-gated x-sec momentum, XR02 reversal vol-gated) -> forward-monitor, non deployabili (panel 2.5y regime unico + STAT-MODE esecuzione). Portafoglio live invariato. Incluso anche options_vrp_managed.py (A/B VRP01 hold-to-expiry vs gestione attiva del doc credit-spread): la gestione attiva DISTRUGGE l'edge (combo FULL managed Sh -1.29 vs HtE +0.96, il delta-exit taglia i vincenti) -> scartata, VRP01 resta hold-to-expiry. Diari: 2026-06-20-xsec-strategies-sweep.md, 2026-06-20-vrp-active-management.md. gitignore: data/paper_portfolio/ (stato runtime paper) + scripts/research/xsec/runs/out/ (output rigenerabile). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
"""XM06 — 52-day-high proximity (closeness-to-recent-high momentum).
|
||||
|
||||
IDEA: Score = close / rolling_max(high, W) [closeness to recent high].
|
||||
Assets near their recent high are "in momentum"; rank them cross-sectionally.
|
||||
W in {60, 90}. Causal: rolling_max up through bar i only.
|
||||
|
||||
Grid: 5 calls max
|
||||
1. W=60, majors, H=10, k=5, L/S
|
||||
2. W=90, majors, H=10, k=5, L/S
|
||||
3. W=60, all, H=10, k=5, L/S (best-W on wider universe)
|
||||
4. W=60, all, H=5, k=5, L/S (faster rebalance)
|
||||
5. W=60, all, H=10, k=7, L/S (wider book)
|
||||
"""
|
||||
import sys
|
||||
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/xsec")
|
||||
import xslib as xs
|
||||
import numpy as np
|
||||
|
||||
|
||||
def score_proximity(P, W):
|
||||
"""Causal: close[i] / max(high[i-W+1 .. i]). Higher = closer to recent high = long."""
|
||||
n, A = P.close.shape
|
||||
out = np.full((n, A), np.nan)
|
||||
# rolling max of high, causal window [i-W+1 .. i]
|
||||
high_df = __import__("pandas").DataFrame(P.high)
|
||||
roll_max = high_df.rolling(W, min_periods=max(2, W // 2)).max().values
|
||||
# proximity ratio: close / recent_high (always in (0,1] if no gap-up above window)
|
||||
out = P.close / roll_max
|
||||
return out
|
||||
|
||||
|
||||
# ---- run grid ----
|
||||
|
||||
results = []
|
||||
|
||||
# 1. W=60, majors, H=10, k=5, L/S
|
||||
rep1 = xs.study_xs("XM06_W60_majors", lambda P: score_proximity(P, 60),
|
||||
universe="majors", H=10, k=5, long_short=True)
|
||||
print(xs.fmt(rep1))
|
||||
results.append(rep1)
|
||||
|
||||
# 2. W=90, majors, H=10, k=5, L/S
|
||||
rep2 = xs.study_xs("XM06_W90_majors", lambda P: score_proximity(P, 90),
|
||||
universe="majors", H=10, k=5, long_short=True)
|
||||
print(xs.fmt(rep2))
|
||||
results.append(rep2)
|
||||
|
||||
# 3. W=60, all, H=10, k=5, L/S
|
||||
rep3 = xs.study_xs("XM06_W60_all", lambda P: score_proximity(P, 60),
|
||||
universe="all", H=10, k=5, long_short=True)
|
||||
print(xs.fmt(rep3))
|
||||
results.append(rep3)
|
||||
|
||||
# 4. W=60, all, H=5, k=5, L/S (faster rebalance)
|
||||
rep4 = xs.study_xs("XM06_W60_all_H5", lambda P: score_proximity(P, 60),
|
||||
universe="all", H=5, k=5, long_short=True)
|
||||
print(xs.fmt(rep4))
|
||||
results.append(rep4)
|
||||
|
||||
# 5. W=60, all, H=10, k=7, L/S (wider book)
|
||||
rep5 = xs.study_xs("XM06_W60_all_k7", lambda P: score_proximity(P, 60),
|
||||
universe="all", H=10, k=7, long_short=True)
|
||||
print(xs.fmt(rep5))
|
||||
results.append(rep5)
|
||||
|
||||
# ---- pick best by: earns_slot > hold-out sharpe > distinctness ----
|
||||
def score_result(r):
|
||||
earns = 1 if r["earns_slot"] else 0
|
||||
adds = 1 if r["marginal"].get("verdict") == "ADDS" else 0
|
||||
hold_sh = r["holdout"].get("sharpe", -999)
|
||||
full_sh = r["full"]["sharpe"]
|
||||
corr_xs01 = abs(r.get("corr_xs01") or 1.0)
|
||||
distinct = 1 if corr_xs01 < 0.6 else 0
|
||||
return (earns, adds, hold_sh, full_sh, distinct)
|
||||
|
||||
best = max(results, key=score_result)
|
||||
print("\n=== BEST CONFIG ===")
|
||||
print(xs.fmt(best))
|
||||
print("JSON:", xs.as_json(best))
|
||||
Reference in New Issue
Block a user