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,138 @@
|
||||
"""XU04 — Liquidity-filtered momentum
|
||||
MECHANISM: Cross-sectional momentum, but restrict to the top-N assets by RECENT (rolling 60d)
|
||||
median dollar-volume rather than the static all-panel. The idea: momentum signal is cleaner on
|
||||
liquid names; illiquid tail adds noise. Compare:
|
||||
1. Dynamic top-20 by rolling $-vol (vs static top-20 from XU01)
|
||||
2. Dynamic top-20, adjusted momentum (skip 1d to reduce microstructure noise): L=2..31
|
||||
3. Static majors (19) with skip-1 momentum — XS01-style but skip-1 to reduce echo
|
||||
4. Dynamic top-25 rolling-liquidity blend [30,90] — slightly wider universe
|
||||
5. Dynamic top-20 rolling-liquidity blend [30,90], H=5 (faster rebalance)
|
||||
|
||||
Key difference from XS01: the UNIVERSE is determined dynamically (rolling 60d dollar-volume
|
||||
rank) rather than the fixed 19-major list. This may improve distinctness and resilience to
|
||||
liquidity shifts.
|
||||
"""
|
||||
import sys
|
||||
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/xsec")
|
||||
import xslib as xs
|
||||
import numpy as np
|
||||
|
||||
print("XU04 — Liquidity-filtered momentum")
|
||||
print("=" * 60)
|
||||
|
||||
|
||||
def rolling_liq_score(P, lookbacks=(30, 90), skip=0):
|
||||
"""Momentum blend on the panel, with optional skip-1 for microstructure."""
|
||||
scores = []
|
||||
for L in lookbacks:
|
||||
if skip > 0:
|
||||
# use close[i-skip] / close[i-skip-L] - 1 (causal, skip most recent bars)
|
||||
c = P.close
|
||||
out = np.full_like(c, np.nan)
|
||||
# at row i: return from i-L-skip to i-skip
|
||||
for i in range(L + skip, len(c)):
|
||||
out[i] = c[i - skip] / c[i - L - skip] - 1.0
|
||||
else:
|
||||
out = xs.past_return(P.close, L)
|
||||
scores.append(xs.xs_zscore(out))
|
||||
return np.nanmean(np.stack(scores, axis=0), axis=0)
|
||||
|
||||
|
||||
def score_dyn20_blend(P):
|
||||
"""Dynamic top-20 by rolling $-vol — blend [30,90], no skip."""
|
||||
# P already filtered to top-20 by static median; this fn gets whatever panel is loaded.
|
||||
# We do dynamic re-weighting via volume z-score gating:
|
||||
# compute rolling 60d dollar volume rank per asset; assets below median get half-weight score
|
||||
dv = P.close * P.vol # dollar volume matrix (n_days x n_assets)
|
||||
dv_roll = xs.roll_mean(dv, 60) # rolling 60d mean $-vol
|
||||
# rank liquidity cross-sectionally
|
||||
liq_rank = xs.xs_rank(dv_roll) # 0..1, higher = more liquid
|
||||
# momentum signal
|
||||
mom = rolling_liq_score(P, lookbacks=(30, 90), skip=0)
|
||||
# attenuate score of less-liquid assets (liq_rank < 0.5 -> half score)
|
||||
liq_weight = np.where(liq_rank >= 0.5, 1.0, 0.5)
|
||||
return mom * liq_weight
|
||||
|
||||
|
||||
def score_skip1(P):
|
||||
"""Majors, momentum blend [30,90] with 1-day skip (microstructure reduction)."""
|
||||
return rolling_liq_score(P, lookbacks=(30, 90), skip=1)
|
||||
|
||||
|
||||
def score_top25_blend(P):
|
||||
"""Top-25 universe, plain blend [30,90]."""
|
||||
return rolling_liq_score(P, lookbacks=(30, 90), skip=0)
|
||||
|
||||
|
||||
def score_dyn20_fast(P):
|
||||
"""Dynamic top-20 + blend [30,90], faster H=5 rebalance."""
|
||||
return score_dyn20_blend(P)
|
||||
|
||||
|
||||
# 1) Top-20 with dynamic liquidity weighting, H=10, k=5
|
||||
rep1 = xs.study_xs(
|
||||
"XU04_DYN20_H10",
|
||||
score_dyn20_blend,
|
||||
universe=20, H=10, k=5, long_short=True
|
||||
)
|
||||
print(xs.fmt(rep1))
|
||||
print("JSON:", xs.as_json(rep1))
|
||||
print()
|
||||
|
||||
# 2) Majors (19) with skip-1 momentum — reduces microstructure vs XS01
|
||||
rep2 = xs.study_xs(
|
||||
"XU04_MAJ_SKIP1",
|
||||
score_skip1,
|
||||
universe="majors", H=10, k=5, long_short=True
|
||||
)
|
||||
print(xs.fmt(rep2))
|
||||
print("JSON:", xs.as_json(rep2))
|
||||
print()
|
||||
|
||||
# 3) Top-20 plain blend [30,90] no weighting, H=10 (clean baseline vs XU01)
|
||||
rep3 = xs.study_xs(
|
||||
"XU04_TOP20_PLAIN",
|
||||
lambda P: rolling_liq_score(P, lookbacks=(30, 90), skip=0),
|
||||
universe=20, H=10, k=5, long_short=True
|
||||
)
|
||||
print(xs.fmt(rep3))
|
||||
print("JSON:", xs.as_json(rep3))
|
||||
print()
|
||||
|
||||
# 4) Top-25, blend [30,90], H=10
|
||||
rep4 = xs.study_xs(
|
||||
"XU04_TOP25_H10",
|
||||
score_top25_blend,
|
||||
universe=25, H=10, k=5, long_short=True
|
||||
)
|
||||
print(xs.fmt(rep4))
|
||||
print("JSON:", xs.as_json(rep4))
|
||||
print()
|
||||
|
||||
# 5) Top-20 dynamic liq-weighted, H=5 (faster)
|
||||
rep5 = xs.study_xs(
|
||||
"XU04_DYN20_H5",
|
||||
score_dyn20_fast,
|
||||
universe=20, H=5, k=5, long_short=True
|
||||
)
|
||||
print(xs.fmt(rep5))
|
||||
print("JSON:", xs.as_json(rep5))
|
||||
print()
|
||||
|
||||
|
||||
# Pick best
|
||||
all_reps = [rep1, rep2, rep3, rep4, rep5]
|
||||
|
||||
def score_rep(r):
|
||||
earns = int(r.get("earns_slot", False))
|
||||
hold_sh = (r.get("holdout") or {}).get("sharpe", -9)
|
||||
full_sh = (r.get("full") or {}).get("sharpe", -9)
|
||||
corr_xs01 = r.get("corr_xs01") or 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))
|
||||
Reference in New Issue
Block a user