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,114 @@
|
||||
"""XL01 — Amihud Illiquidity Premium (cross-sectional).
|
||||
|
||||
Score = rolling mean of |ret| / (close * volume) over W days (Amihud ratio).
|
||||
Higher score = more illiquid.
|
||||
|
||||
We test both signs:
|
||||
- Long illiquid (higher score = long): illiquidity premium hypothesis
|
||||
- Short illiquid (higher score = short): liquidity premium, more liquid = better
|
||||
|
||||
Grid (<=5 calls):
|
||||
1. LS W=30, all universe
|
||||
2. LS W=30, majors
|
||||
3. LS W=30, short sign (liquidity premium, flip sign)
|
||||
4. LS W=30, H=20 (slower rebal), all universe
|
||||
5. LS W=60, all universe
|
||||
"""
|
||||
import sys
|
||||
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/xsec")
|
||||
import xslib as xs
|
||||
import numpy as np
|
||||
|
||||
|
||||
def amihud_score(close, vol, ret, W=30):
|
||||
"""Amihud illiquidity ratio: mean(|ret| / (close * volume)) over W days.
|
||||
Higher = more illiquid.
|
||||
Values at bar i use data <= i (causal).
|
||||
"""
|
||||
# dollar volume = close * volume (notional traded)
|
||||
dollar_vol = close * vol # (n, A)
|
||||
# |return| / dollar_vol
|
||||
abs_ret = np.abs(ret) # (n, A)
|
||||
# avoid division by zero
|
||||
dv_safe = np.where(dollar_vol > 0, dollar_vol, np.nan)
|
||||
amihud_raw = abs_ret / dv_safe # (n, A)
|
||||
# rolling mean (causal)
|
||||
score = xs.roll_mean(amihud_raw, W)
|
||||
return score
|
||||
|
||||
|
||||
def score_illiquid(W=30):
|
||||
"""Long illiquid (high Amihud = illiquid -> buy)."""
|
||||
def fn(P):
|
||||
return amihud_score(P.close, P.vol, P.ret, W=W)
|
||||
return fn
|
||||
|
||||
|
||||
def score_liquid(W=30):
|
||||
"""Long liquid (flip sign: low Amihud = liquid -> buy)."""
|
||||
def fn(P):
|
||||
return -amihud_score(P.close, P.vol, P.ret, W=W)
|
||||
return fn
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("XL01 — Amihud Illiquidity Premium")
|
||||
print("="*60)
|
||||
|
||||
# 1. Baseline: long illiquid, W=30, all universe
|
||||
print("\n[1] Long ILLIQUID, W=30, universe=all, H=10, k=5, LS")
|
||||
r1 = xs.study_xs("XL01-ILL-30-all", score_illiquid(30),
|
||||
universe="all", H=10, k=5, long_short=True)
|
||||
print(xs.fmt(r1))
|
||||
print("JSON:", xs.as_json(r1))
|
||||
|
||||
# 2. Long illiquid, W=30, majors only
|
||||
print("\n[2] Long ILLIQUID, W=30, universe=majors, H=10, k=5, LS")
|
||||
r2 = xs.study_xs("XL01-ILL-30-maj", score_illiquid(30),
|
||||
universe="majors", H=10, k=5, long_short=True)
|
||||
print(xs.fmt(r2))
|
||||
print("JSON:", xs.as_json(r2))
|
||||
|
||||
# 3. Long LIQUID (flip sign), W=30, all universe
|
||||
print("\n[3] Long LIQUID (flip sign), W=30, universe=all, H=10, k=5, LS")
|
||||
r3 = xs.study_xs("XL01-LIQ-30-all", score_liquid(30),
|
||||
universe="all", H=10, k=5, long_short=True)
|
||||
print(xs.fmt(r3))
|
||||
print("JSON:", xs.as_json(r3))
|
||||
|
||||
# 4. Long illiquid, W=30, H=20 (slower rebal), all
|
||||
print("\n[4] Long ILLIQUID, W=30, universe=all, H=20, k=5, LS")
|
||||
r4 = xs.study_xs("XL01-ILL-30-H20", score_illiquid(30),
|
||||
universe="all", H=20, k=5, long_short=True)
|
||||
print(xs.fmt(r4))
|
||||
print("JSON:", xs.as_json(r4))
|
||||
|
||||
# 5. Long illiquid, W=60, all universe
|
||||
print("\n[5] Long ILLIQUID, W=60, universe=all, H=10, k=5, LS")
|
||||
r5 = xs.study_xs("XL01-ILL-60-all", score_illiquid(60),
|
||||
universe="all", H=10, k=5, long_short=True)
|
||||
print(xs.fmt(r5))
|
||||
print("JSON:", xs.as_json(r5))
|
||||
|
||||
# Summary
|
||||
results = [r1, r2, r3, r4, r5]
|
||||
print("\n" + "="*60)
|
||||
print("SUMMARY — pick best by: earns_slot > holdout > distinctness")
|
||||
for r in results:
|
||||
es = r["earns_slot"]
|
||||
fsh = r["full"]["sharpe"]
|
||||
hsh = r["holdout"].get("sharpe", 0)
|
||||
cxs = r["corr_xs01"]
|
||||
v = r["marginal"]["verdict"]
|
||||
print(f" {r['name']:30s} FULL={fsh:+.2f} HOLD={hsh:+.2f} corr_xs01={cxs} "
|
||||
f"verdict={v} earns_slot={es}")
|
||||
|
||||
# Pick best: prefer earns_slot, then hold sharpe
|
||||
best = max(results, key=lambda r: (
|
||||
r["earns_slot"],
|
||||
r["holdout"].get("sharpe", -99),
|
||||
r["full"]["sharpe"],
|
||||
))
|
||||
print(f"\nBEST CONFIG: {best['name']}")
|
||||
print(xs.fmt(best))
|
||||
print("BEST JSON:", xs.as_json(best))
|
||||
Reference in New Issue
Block a user