9612560479
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>
102 lines
3.4 KiB
Python
102 lines
3.4 KiB
Python
"""XV05 — Low Max-Drawdown Anomaly
|
|
Score = -rolling_maxdrawdown(close, W) over the past W bars.
|
|
Prefer assets with smooth price history (low drawdown) for long,
|
|
prefer highly-drawn-down assets for short.
|
|
|
|
Grid: vary W (30, 60, 90), universe (majors, all), H (10).
|
|
<=5 study_xs calls total.
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/xsec")
|
|
import xslib as xs
|
|
import numpy as np
|
|
|
|
|
|
def rolling_maxdd(close, W):
|
|
"""Causal rolling max-drawdown over the past W bars.
|
|
At row i: max drawdown of the window [i-W+1 .. i].
|
|
Returns matrix (n_days x n_assets). NaN for first W-1 rows.
|
|
Higher = worse drawdown (more negative).
|
|
"""
|
|
n, A = close.shape
|
|
out = np.full((n, A), np.nan)
|
|
for i in range(W - 1, n):
|
|
window = close[i - W + 1: i + 1] # shape (W, A) — causal: data <= i
|
|
# rolling peak up to each bar within window
|
|
peak = np.maximum.accumulate(window, axis=0)
|
|
dd = (window - peak) / peak # drawdown at each bar (<=0)
|
|
out[i] = np.nanmin(dd, axis=0) # worst drawdown in window (most negative)
|
|
return out
|
|
|
|
|
|
def score_fn_w60(P):
|
|
"""Score = -maxDD(W=60): prefer LOW drawdown (smooth equity)."""
|
|
return -rolling_maxdd(P.close, 60)
|
|
|
|
|
|
def score_fn_w30(P):
|
|
"""Score = -maxDD(W=30): shorter memory."""
|
|
return -rolling_maxdd(P.close, 30)
|
|
|
|
|
|
def score_fn_w90(P):
|
|
"""Score = -maxDD(W=90): longer memory."""
|
|
return -rolling_maxdd(P.close, 90)
|
|
|
|
|
|
def score_fn_w60_blend(P):
|
|
"""Blend: average score from W=30 and W=90 (multi-horizon like XS01 blend)."""
|
|
s30 = -rolling_maxdd(P.close, 30)
|
|
s90 = -rolling_maxdd(P.close, 90)
|
|
return xs.xs_zscore(s30) + xs.xs_zscore(s90)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("=== XV05: Low Max-Drawdown Anomaly ===\n")
|
|
|
|
# Run 1: canonical W=60, majors universe, H=10, k=5, long-short
|
|
print("--- Run 1: W=60, majors, H=10, k=5, LS ---")
|
|
r1 = xs.study_xs("XV05-W60-maj", score_fn_w60, universe="majors", H=10, k=5, long_short=True)
|
|
print(xs.fmt(r1))
|
|
print()
|
|
|
|
# Run 2: W=60, all universe (49 alts)
|
|
print("--- Run 2: W=60, all, H=10, k=5, LS ---")
|
|
r2 = xs.study_xs("XV05-W60-all", score_fn_w60, universe="all", H=10, k=5, long_short=True)
|
|
print(xs.fmt(r2))
|
|
print()
|
|
|
|
# Run 3: W=30, majors
|
|
print("--- Run 3: W=30, majors, H=10, k=5, LS ---")
|
|
r3 = xs.study_xs("XV05-W30-maj", score_fn_w30, universe="majors", H=10, k=5, long_short=True)
|
|
print(xs.fmt(r3))
|
|
print()
|
|
|
|
# Run 4: W=90, majors
|
|
print("--- Run 4: W=90, majors, H=10, k=5, LS ---")
|
|
r4 = xs.study_xs("XV05-W90-maj", score_fn_w90, universe="majors", H=10, k=5, long_short=True)
|
|
print(xs.fmt(r4))
|
|
print()
|
|
|
|
# Run 5: blend W=30+W=90, all universe
|
|
print("--- Run 5: Blend W30+W90, all, H=10, k=5, LS ---")
|
|
r5 = xs.study_xs("XV05-BLENDall", score_fn_w60_blend, universe="all", H=10, k=5, long_short=True)
|
|
print(xs.fmt(r5))
|
|
print()
|
|
|
|
# Pick best by earns_slot, then hold-out sharpe, then distinctness from XS01
|
|
results = [r1, r2, r3, r4, r5]
|
|
names = ["W60-maj", "W60-all", "W30-maj", "W90-maj", "Blend-all"]
|
|
|
|
def score_key(r):
|
|
earns = 1 if r["earns_slot"] else 0
|
|
hold_sh = r["holdout"].get("sharpe", -99)
|
|
full_sh = r["full"]["sharpe"]
|
|
xs01_corr = abs(r["corr_xs01"] or 1.0)
|
|
return (earns, hold_sh, full_sh, -xs01_corr)
|
|
|
|
best = max(results, key=score_key)
|
|
print("\n=== BEST CONFIG ===")
|
|
print(xs.fmt(best))
|
|
print("JSON:", xs.as_json(best))
|