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

73 lines
2.7 KiB
Python

"""XM04 — Residual / Idiosyncratic Momentum
IDEA: Instead of raw past return, score = cumulative idiosyncratic (beta-removed) return
over the last L days. Should be a cleaner momentum signal: strips out the common market
component and scores assets on their STOCK-SPECIFIC performance.
Signal: for each day i and asset a, sum the daily residual_returns over [i-L+1 .. i].
residual_ret[t,a] = ret[t,a] - beta_t_a * market_ret[t]
score[i,a] = sum(residual_ret[i-L+1:i+1, a]) (causal: uses data <= i)
Grid (<=5 calls):
1. XM04-L30-maj : majors universe, L=30, H=10, k=5, LS
2. XM04-L60-maj : majors universe, L=60, H=10, k=5, LS
3. XM04-L30-all : all universe, L=30, H=10, k=5, LS
4. XM04-L30-maj-H5: majors, L=30, H=5, k=5, LS (faster rebal)
5. XM04-L30-maj-LO: majors, L=30, H=10, k=5, long-only (LO)
"""
import sys
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/xsec")
import xslib as xs
import numpy as np
def resid_mom_score(P, L=30, beta_win=60):
"""Cumulative residual return over the last L days.
residual_ret[t,a] = ret[t,a] - beta(win)*market_ret[t]
score[i,a] = rolling sum of residual_ret over window L.
All causal: roll_beta uses data <=i, rolling sum uses [i-L+1..i].
"""
# daily idiosyncratic returns (n_days x n_assets), causal
resid = xs.residual_return(P.ret, win=beta_win)
# rolling sum over L days = cumulative idiosyncratic momentum
score = xs.roll_mean(resid, L) * L # equiv to rolling sum (roll_mean * win)
return score
configs = [
# name, universe, L, H, k, long_short
("XM04-L30-maj", "majors", 30, 10, 5, True),
("XM04-L60-maj", "majors", 60, 10, 5, True),
("XM04-L30-all", "all", 30, 10, 5, True),
("XM04-L30-maj-H5", "majors", 30, 5, 5, True),
("XM04-L30-maj-LO", "majors", 30, 10, 5, False),
]
results = []
for name, univ, L, H, k, ls in configs:
print(f"\nRunning {name} ...")
rep = xs.study_xs(
name,
lambda P, _L=L: resid_mom_score(P, L=_L, beta_win=60),
universe=univ,
H=H,
k=k,
long_short=ls,
)
print(xs.fmt(rep))
results.append(rep)
# Pick best: prefer earns_slot, then highest hold-out Sharpe, then most distinct from XS01
def score_config(r):
earns = r["earns_slot"]
hold_sh = r["holdout"].get("sharpe", -99)
full_sh = r["full"]["sharpe"]
corr_xs = r["corr_xs01"] or 1.0
# primary: earns_slot; secondary: holdout Sharpe; tiebreak: distinctness
return (earns, hold_sh, full_sh, -abs(corr_xs))
best = max(results, key=score_config)
print("\n" + "="*60)
print("BEST CONFIG:")
print(xs.fmt(best))
print("JSON:", xs.as_json(best))