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:
Adriano Dal Pastro
2026-06-20 21:36:57 +00:00
parent 5ac4e16af8
commit 9612560479
50 changed files with 5457 additions and 0 deletions
+106
View File
@@ -0,0 +1,106 @@
"""XV03 — Betting Against Beta (BAB) — Low-beta anomaly
MECHANISM: Score = -roll_beta(ret, W) (long low-beta alts / short high-beta alts).
The BAB anomaly (Frazzini & Pedersen 2014): within an asset cross-section, lower-beta
assets deliver higher risk-adjusted returns — because levered/constrained investors
bid up high-beta assets above fair value. Score = NEGATIVE rolling beta to equal-weight
market, so top-ranked = lowest beta.
Grid: beta window W in {30, 60}; universe in {all, majors}; long-short.
Also test: blend BAB + dispersion condition (only enter if cross-sectional vol is high).
"""
import sys
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/xsec")
import xslib as xs
import numpy as np
print("XV03 — Betting Against Beta (BAB)")
print("=" * 60)
# --------------------------------------------------------------------------
# Score functions
# --------------------------------------------------------------------------
def score_bab(ret, win):
"""BAB score: negative rolling beta to equal-weight market (causal)."""
beta = xs.roll_beta(ret, win) # (n,A): higher = more market exposure
return -beta # higher score = lower beta = long candidate
def score_bab_beta_adj(ret, win):
"""BAB score adjusted: z-score the negative beta cross-sectionally."""
return xs.xs_zscore(-xs.roll_beta(ret, win))
# --------------------------------------------------------------------------
# Run 5 targeted backtests
# --------------------------------------------------------------------------
# 1) All alts, W=30 (shorter window — more reactive), LS
rep1 = xs.study_xs(
"XV03_ALL_W30_LS",
lambda P: score_bab(P.ret, 30),
universe="all", H=10, k=5, long_short=True
)
print(xs.fmt(rep1))
print("JSON:", xs.as_json(rep1))
print()
# 2) All alts, W=60 (longer window — more stable beta estimates), LS
rep2 = xs.study_xs(
"XV03_ALL_W60_LS",
lambda P: score_bab(P.ret, 60),
universe="all", H=10, k=5, long_short=True
)
print(xs.fmt(rep2))
print("JSON:", xs.as_json(rep2))
print()
# 3) Majors only (19 XS01 assets), W=60, LS
# Cleaner universe: major liquid alts, should reduce noise
rep3 = xs.study_xs(
"XV03_MAJORS_W60_LS",
lambda P: score_bab(P.ret, 60),
universe="majors", H=10, k=5, long_short=True
)
print(xs.fmt(rep3))
print("JSON:", xs.as_json(rep3))
print()
# 4) All alts, W=60, XS-zscored BAB, shorter rebalance H=5
# XS z-score normalizes the beta signal each day cross-sectionally
rep4 = xs.study_xs(
"XV03_ALL_W60_ZS_H5",
lambda P: score_bab_beta_adj(P.ret, 60),
universe="all", H=5, k=5, long_short=True
)
print(xs.fmt(rep4))
print("JSON:", xs.as_json(rep4))
print()
# 5) BAB blend: combine W=30 and W=60 betas (multi-horizon, inspired by XS01 blend)
# Average the two z-scored BAB signals
rep5 = xs.study_xs(
"XV03_ALL_BLEND3060_LS",
lambda P: xs.xs_zscore(score_bab(P.ret, 30)) + xs.xs_zscore(score_bab(P.ret, 60)),
universe="all", H=10, k=5, long_short=True
)
print(xs.fmt(rep5))
print("JSON:", xs.as_json(rep5))
print()
# --------------------------------------------------------------------------
# Pick best: earns_slot > hold-out sharpe > distinctness from XS01
# --------------------------------------------------------------------------
all_reps = [rep1, rep2, rep3, rep4, rep5]
def score_rep(r):
earns = int(r["earns_slot"])
hold_sh = r["holdout"].get("sharpe", -9)
full_sh = r["full"]["sharpe"]
corr_xs01 = r["corr_xs01"] if r["corr_xs01"] is not None else 1.0
distinctness = 1 - abs(corr_xs01)
return (earns, hold_sh, full_sh, distinctness)
best = max(all_reps, key=score_rep)
print("=" * 60)
print(f"BEST CONFIG: {best['name']}")
print(xs.fmt(best))
print("JSON:", xs.as_json(best))