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>
89 lines
2.6 KiB
Python
89 lines
2.6 KiB
Python
"""XS06b — Correlation-to-market diversifier.
|
|
|
|
Score = -rolling_corr(asset_ret, market_ret, 60)
|
|
Long the assets LEAST correlated to the equal-weight market (the "divergers"),
|
|
short the most-correlated ones. win=60 days.
|
|
|
|
Idea: if cross-sectional momentum (XS01) selects by recent past return, this
|
|
selects by structural independence from the pack — a fundamentally different
|
|
axis. The two should be weakly correlated.
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/xsec")
|
|
import xslib as xs
|
|
import numpy as np
|
|
import pandas as pd
|
|
|
|
|
|
def score_corr_diversifier(P, win=60):
|
|
"""Score = -rolling_corr(asset_ret, market_ret, win). Causal."""
|
|
n, A = P.ret.shape
|
|
mkt = xs.market_ret(P.ret) # (n,) equal-weight market
|
|
|
|
out = np.full((n, A), np.nan)
|
|
mkt_s = pd.Series(mkt)
|
|
|
|
for a in range(A):
|
|
asset_s = pd.Series(P.ret[:, a])
|
|
# rolling correlation — pandas rolling corr is causal
|
|
corr = asset_s.rolling(win, min_periods=max(10, win // 2)).corr(mkt_s)
|
|
# score = NEGATIVE correlation: higher => less correlated => long
|
|
out[:, a] = -corr.values
|
|
|
|
return out
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Grid: 5 study_xs calls max
|
|
# - vary universe (all vs majors)
|
|
# - vary H (rebalance freq)
|
|
# - vary long_short
|
|
# ---------------------------------------------------------------------------
|
|
|
|
print("=" * 70)
|
|
print("XS06b — Correlation-to-market diversifier (score = -roll_corr_60)")
|
|
print("=" * 70)
|
|
|
|
best = None
|
|
best_earns = False
|
|
best_ho = -999
|
|
|
|
configs = [
|
|
# (label_suffix, universe, H, k, long_short)
|
|
("all_H10_k5_ls", "all", 10, 5, True),
|
|
("maj_H10_k5_ls", "majors", 10, 5, True),
|
|
("all_H5_k5_ls", "all", 5, 5, True),
|
|
("all_H10_k5_lo", "all", 10, 5, False),
|
|
("all_H20_k5_ls", "all", 20, 5, True),
|
|
]
|
|
|
|
results = []
|
|
for (suffix, universe, H, k, ls) in configs:
|
|
name = f"XS06b_{suffix}"
|
|
print(f"\n--- {name} ---")
|
|
rep = xs.study_xs(
|
|
name,
|
|
lambda P: score_corr_diversifier(P, win=60),
|
|
universe=universe,
|
|
H=H,
|
|
k=k,
|
|
long_short=ls,
|
|
target_vol=0.20,
|
|
)
|
|
print(xs.fmt(rep))
|
|
print("JSON:", xs.as_json(rep))
|
|
results.append(rep)
|
|
|
|
# track best: earns_slot first, then hold-out sharpe
|
|
earns = rep.get("earns_slot", False)
|
|
ho_sh = rep.get("holdout", {}).get("sharpe", -999)
|
|
if (earns and not best_earns) or (earns == best_earns and ho_sh > best_ho):
|
|
best = rep
|
|
best_earns = earns
|
|
best_ho = ho_sh
|
|
|
|
print("\n" + "=" * 70)
|
|
print("BEST CONFIG:")
|
|
print(xs.fmt(best))
|
|
print("JSON:", xs.as_json(best))
|