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
+132
View File
@@ -0,0 +1,132 @@
"""XS05b — Risk-parity momentum (inverse-vol weighted legs).
MECHANISM: Select top-k / bottom-k by plain 60-day momentum (same as XS01),
but instead of equal-weighting within long/short legs, weight each asset by
INVERSE of its own recent volatility (60-day rolling std of daily returns).
This approximates risk-parity within the cross-sectional book: lower-vol
assets get larger weight, so each leg contributes roughly equal risk.
LIMITATION / CAVEAT:
- xslib.study_xs always equal-weights within legs (the score only determines
SELECTION, not position sizing). We cannot pass per-asset weights directly
through the study_xs interface.
- Workaround: encode the inverse-vol signal INTO the score. After selecting
the top-k / bottom-k by momentum rank, the harness will still equal-weight
— but by blending the momentum z-score with the inverse-vol z-score we bias
the SELECTION toward low-vol winners (i.e., the most risk-efficient longs
rank higher). This is a partial approximation: true risk-parity would rescale
weights post-selection; here we rescale the ranking pre-selection.
- The blend is: score = z(mom60) + alpha * z(1/vol60), where alpha=1 gives
equal weight to momentum rank and inverse-vol rank.
GRID (<=5 calls):
1. XS05b-base : majors, H=10, k=5, L=60, alpha=1 (blend)
2. XS05b-all : all (49 alts), H=10, k=5, L=60, alpha=1
3. XS05b-a05 : majors, H=10, k=5, L=60, alpha=0.5 (lighter inv-vol)
4. XS05b-a2 : majors, H=10, k=5, L=60, alpha=2.0 (heavier inv-vol)
5. XS05b-H5 : majors, H=5, k=5, L=60, alpha=1 (faster rebalance)
"""
import sys
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/xsec")
import xslib as xs
import numpy as np
def score_xs05b(P, L=60, alpha=1.0):
"""Risk-parity momentum score (causal).
score = z_cross(mom_L) + alpha * z_cross(inv_vol_L)
Higher score -> more risk-efficient momentum winner -> long.
Lower score -> more risk-efficient momentum loser -> short.
"""
# 1. momentum signal (L-day return, causal)
mom = xs.past_return(P.close, L) # (n_days, n_assets), uses close[i-L:i]
z_mom = xs.xs_zscore(mom)
# 2. inverse-vol signal (rolling std of daily returns, causal)
vol = xs.roll_std(P.ret, L) # (n_days, n_assets)
inv_vol = np.where(vol > 0, 1.0 / vol, np.nan)
z_inv_vol = xs.xs_zscore(inv_vol)
# 3. blend
score = z_mom + alpha * z_inv_vol
return score
results = {}
# --- Config 1: majors, H=10, k=5, alpha=1 (baseline blend) ---
rep1 = xs.study_xs(
"XS05b-base",
lambda P: score_xs05b(P, L=60, alpha=1.0),
universe="majors",
H=10, k=5, long_short=True
)
results["XS05b-base"] = rep1
print(xs.fmt(rep1))
print("JSON:", xs.as_json(rep1))
print()
# --- Config 2: all alts, H=10, k=5, alpha=1 ---
rep2 = xs.study_xs(
"XS05b-all",
lambda P: score_xs05b(P, L=60, alpha=1.0),
universe="all",
H=10, k=5, long_short=True
)
results["XS05b-all"] = rep2
print(xs.fmt(rep2))
print("JSON:", xs.as_json(rep2))
print()
# --- Config 3: majors, H=10, k=5, alpha=0.5 (lighter inv-vol) ---
rep3 = xs.study_xs(
"XS05b-a05",
lambda P: score_xs05b(P, L=60, alpha=0.5),
universe="majors",
H=10, k=5, long_short=True
)
results["XS05b-a05"] = rep3
print(xs.fmt(rep3))
print("JSON:", xs.as_json(rep3))
print()
# --- Config 4: majors, H=10, k=5, alpha=2.0 (heavier inv-vol) ---
rep4 = xs.study_xs(
"XS05b-a2",
lambda P: score_xs05b(P, L=60, alpha=2.0),
universe="majors",
H=10, k=5, long_short=True
)
results["XS05b-a2"] = rep4
print(xs.fmt(rep4))
print("JSON:", xs.as_json(rep4))
print()
# --- Config 5: majors, H=5, k=5, alpha=1 (faster rebalance) ---
rep5 = xs.study_xs(
"XS05b-H5",
lambda P: score_xs05b(P, L=60, alpha=1.0),
universe="majors",
H=5, k=5, long_short=True
)
results["XS05b-H5"] = rep5
print(xs.fmt(rep5))
print("JSON:", xs.as_json(rep5))
print()
# --- Summary ---
print("=" * 60)
print("SUMMARY — XS05b grid")
print("=" * 60)
fmt_h = f"{'Config':<16} {'FullSh':>7} {'HoldSh':>7} {'MaxDD':>7} {'CorrXS01':>9} {'EarnsSlot':>10} {'Verdict':>10}"
print(fmt_h)
print("-" * 70)
for name, r in results.items():
fs = r["full"]["sharpe"]
hs = r["holdout"]["sharpe"]
dd = r["full"]["maxdd"]
cxs = r.get("corr_xs01", float("nan"))
es = r.get("earns_slot", False)
vd = r.get("marginal", {}).get("verdict", "N/A")
print(f"{name:<16} {fs:>7.2f} {hs:>7.2f} {dd:>7.2f} {cxs:>9.3f} {str(es):>10} {vd:>10}")