Files
Adriano Dal Pastro 9612560479 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>
2026-06-20 21:36:57 +00:00

95 lines
2.9 KiB
Python

"""XVa3 — Price-to-high value (mean reversion from recent highs).
IDEA: Score = -(close / rolling_max(close, W))
Long the most beaten-down assets vs their rolling high (W=90).
Negative sign: lower ratio (more beaten down) -> higher score -> long.
CAUSAL: rolling_max at row i uses only data[i-W+1 .. i] (pandas rolling handles this).
"""
import sys
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/xsec")
import xslib as xs
import numpy as np
def score_pth(close, W):
"""Price-to-high score: -(close / rolling_max(close, W)), causal."""
import pandas as pd
df = pd.DataFrame(close)
roll_max = df.rolling(W, min_periods=W // 2).max().values
ratio = close / np.where(roll_max > 0, roll_max, np.nan)
return -ratio # lower ratio (more beaten down) -> higher score -> long
# --- Grid: 5 backtests total ---
# Config 1: canonical W=90, H=10, k=5, long-short, all universe
r1 = xs.study_xs(
"XVa3-W90-H10-k5-LS-all",
lambda P: score_pth(P.close, 90),
universe="all", H=10, k=5, long_short=True,
)
print(xs.fmt(r1))
print("JSON:", xs.as_json(r1))
print()
# Config 2: W=60 (shorter lookback), H=10, k=5, long-short, all universe
r2 = xs.study_xs(
"XVa3-W60-H10-k5-LS-all",
lambda P: score_pth(P.close, 60),
universe="all", H=10, k=5, long_short=True,
)
print(xs.fmt(r2))
print("JSON:", xs.as_json(r2))
print()
# Config 3: W=90, H=5 (faster rebalance), k=5, long-short, all
r3 = xs.study_xs(
"XVa3-W90-H5-k5-LS-all",
lambda P: score_pth(P.close, 90),
universe="all", H=5, k=5, long_short=True,
)
print(xs.fmt(r3))
print("JSON:", xs.as_json(r3))
print()
# Config 4: W=90, H=10, k=5, majors only (more liquid)
r4 = xs.study_xs(
"XVa3-W90-H10-k5-LS-majors",
lambda P: score_pth(P.close, 90),
universe="majors", H=10, k=5, long_short=True,
)
print(xs.fmt(r4))
print("JSON:", xs.as_json(r4))
print()
# Config 5: W=120 (longer lookback), H=10, k=5, long-short, all
r5 = xs.study_xs(
"XVa3-W120-H10-k5-LS-all",
lambda P: score_pth(P.close, 120),
universe="all", H=10, k=5, long_short=True,
)
print(xs.fmt(r5))
print("JSON:", xs.as_json(r5))
print()
# --- Pick best config ---
# Prefer: earns_slot first, then holdout sharpe, then distinctness
results = [r1, r2, r3, r4, r5]
earns = [r for r in results if r["earns_slot"]]
if earns:
best = max(earns, key=lambda r: r["holdout"].get("sharpe", -999))
else:
# Fall back to positive full+hold, distinct from XS01
candidates = [r for r in results
if r["full"]["sharpe"] > 0
and r["holdout"].get("sharpe", 0) > 0
and (r["corr_xs01"] or 1.0) < 0.6]
if candidates:
best = max(candidates, key=lambda r: r["holdout"].get("sharpe", -999))
else:
best = max(results, key=lambda r: r["holdout"].get("sharpe", -999))
print("=== BEST CONFIG ===")
print(xs.fmt(best))
print("JSON:", xs.as_json(best))