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,137 @@
|
||||
"""XU03 — Long-Only Top-k (Alt Selection)
|
||||
MECHANISM: Low-vol / momentum LONG-ONLY top-k alt selection.
|
||||
- NOT market-neutral: goes long only the top-k alts by combined score, flat otherwise.
|
||||
- Captures alt-beta + selection effect (distinct from XS01 which is market-neutral).
|
||||
- Executable at small capital (k legs, no short book needed).
|
||||
|
||||
Signal: blend of momentum (z30+z90) and low-vol (-rv30) in a composite score.
|
||||
The combined signal selects alts that are trending UP and relatively stable.
|
||||
long_short=False -> long-only top-k, no short leg.
|
||||
|
||||
Grid (5 backtests):
|
||||
1. MOM_LO H=10 k=5 universe=majors — baseline long-only momentum
|
||||
2. MOM_LO H=10 k=5 universe=all — wider universe, more selection power
|
||||
3. COMBO H=10 k=5 universe=majors — blend momentum + low-vol (composite)
|
||||
4. COMBO H=20 k=5 universe=majors — slower rebalance, lower turnover
|
||||
5. COMBO H=10 k=3 universe=majors — tighter portfolio (top-3 only)
|
||||
|
||||
Hypothesis: long-only selection will have high corr_tp01 (market beta) but low corr_xs01
|
||||
(market-neutral XS01 cancels market beta). If the composite score selects quality alts that
|
||||
outperform TP01 (BTC/ETH only), it adds informational value.
|
||||
"""
|
||||
import sys
|
||||
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/xsec")
|
||||
import xslib as xs
|
||||
import numpy as np
|
||||
|
||||
print("XU03 — Long-Only Top-k (Alt Selection: Momentum + Low-Vol Composite)")
|
||||
print("=" * 70)
|
||||
|
||||
|
||||
def mom_blend(P):
|
||||
"""Z-blend of 30d and 90d momentum — same signal as XS01 but long-only."""
|
||||
z30 = xs.xs_zscore(xs.past_return(P.close, 30))
|
||||
z90 = xs.xs_zscore(xs.past_return(P.close, 90))
|
||||
return np.nanmean(np.stack([z30, z90], axis=0), axis=0)
|
||||
|
||||
|
||||
def combo_score(P):
|
||||
"""Composite: momentum blend + low-vol preference.
|
||||
Selects alts that are trending up AND have lower realized volatility.
|
||||
Both components are cross-sectionally z-scored before blending.
|
||||
"""
|
||||
# Momentum: 30d + 90d blend
|
||||
z30 = xs.xs_zscore(xs.past_return(P.close, 30))
|
||||
z90 = xs.xs_zscore(xs.past_return(P.close, 90))
|
||||
z_mom = np.nanmean(np.stack([z30, z90], axis=0), axis=0)
|
||||
|
||||
# Low-vol: prefer stable alts (negate RV so higher = lower vol = preferred)
|
||||
rv = xs.roll_std(P.ret, 30)
|
||||
z_lvol = xs.xs_zscore(-rv)
|
||||
|
||||
# Equal blend: 50% momentum + 50% low-vol
|
||||
combo = np.nanmean(np.stack([z_mom, z_lvol], axis=0), axis=0)
|
||||
return combo
|
||||
|
||||
|
||||
# 1) Pure momentum long-only, majors universe — baseline
|
||||
rep1 = xs.study_xs(
|
||||
"XU03_MOM_LO_H10k5_majors",
|
||||
mom_blend,
|
||||
universe="majors", H=10, k=5, long_short=False
|
||||
)
|
||||
print(xs.fmt(rep1))
|
||||
print("JSON:", xs.as_json(rep1))
|
||||
print()
|
||||
|
||||
# 2) Pure momentum long-only, all universe — tests wider selection
|
||||
rep2 = xs.study_xs(
|
||||
"XU03_MOM_LO_H10k5_all",
|
||||
mom_blend,
|
||||
universe="all", H=10, k=5, long_short=False
|
||||
)
|
||||
print(xs.fmt(rep2))
|
||||
print("JSON:", xs.as_json(rep2))
|
||||
print()
|
||||
|
||||
# 3) Composite (mom + low-vol) long-only, majors — main hypothesis
|
||||
rep3 = xs.study_xs(
|
||||
"XU03_COMBO_H10k5_majors",
|
||||
combo_score,
|
||||
universe="majors", H=10, k=5, long_short=False
|
||||
)
|
||||
print(xs.fmt(rep3))
|
||||
print("JSON:", xs.as_json(rep3))
|
||||
print()
|
||||
|
||||
# 4) Composite, slower rebalance H=20 — lower turnover, more patient selection
|
||||
rep4 = xs.study_xs(
|
||||
"XU03_COMBO_H20k5_majors",
|
||||
combo_score,
|
||||
universe="majors", H=20, k=5, long_short=False
|
||||
)
|
||||
print(xs.fmt(rep4))
|
||||
print("JSON:", xs.as_json(rep4))
|
||||
print()
|
||||
|
||||
# 5) Composite, tighter k=3 — more concentrated, highest-conviction picks only
|
||||
rep5 = xs.study_xs(
|
||||
"XU03_COMBO_H10k3_majors",
|
||||
combo_score,
|
||||
universe="majors", H=10, k=3, long_short=False
|
||||
)
|
||||
print(xs.fmt(rep5))
|
||||
print("JSON:", xs.as_json(rep5))
|
||||
print()
|
||||
|
||||
# Summary
|
||||
print("=" * 70)
|
||||
print("SUMMARY: All 5 configs ranked by hold-out Sharpe")
|
||||
all_reps = [rep1, rep2, rep3, rep4, rep5]
|
||||
ranked = sorted(all_reps, key=lambda r: r["holdout"].get("sharpe", -999), reverse=True)
|
||||
for r in ranked:
|
||||
h_sh = r["holdout"].get("sharpe", 0)
|
||||
f_sh = r["full"]["sharpe"]
|
||||
c_xs01 = r["corr_xs01"]
|
||||
c_tp01 = r["corr_tp01"]
|
||||
verdict = r["marginal"].get("verdict", "N/A")
|
||||
earns = r["earns_slot"]
|
||||
print(f" {r['name']:35s} FULL={f_sh:+.2f} HOLD={h_sh:+.2f} "
|
||||
f"corr_xs01={c_xs01:+.2f} corr_tp01={c_tp01:+.2f} "
|
||||
f"verdict={verdict} earns_slot={earns}")
|
||||
|
||||
# Pick best config by: earns_slot first, then hold-out > 0 + distinct, then hold-out
|
||||
best = None
|
||||
for r in ranked:
|
||||
if r["earns_slot"]:
|
||||
best = r
|
||||
break
|
||||
if best is None:
|
||||
candidates = [r for r in ranked
|
||||
if (r.get("corr_xs01") or 1.0) < 0.6 and r["holdout"].get("sharpe", 0) > 0]
|
||||
best = candidates[0] if candidates else ranked[0]
|
||||
|
||||
print()
|
||||
print("BEST CONFIG:")
|
||||
print(xs.fmt(best))
|
||||
print("JSON:", xs.as_json(best))
|
||||
Reference in New Issue
Block a user