d25d897fd1
Origine: gioco "Blind Traders" (100 agenti ciechi su BTC/ETH anonimizzati) -> vincitore = spread ETH/BTC reversion a 15m. Testato sul serio col gate PORT06: non duplicato (corr 1h vs 15m = 0.37), robusto (16/16 celle Sharpe>1), edge NON artefatto delle candele flat ETH 15m (filtrandole resta l'83% dello Sharpe). Percorso live costruito e validato: - pairs_research.pairs_sim_flat: engine generalizzato con exit LIVE-REALIZABLE (arma exit_ready, esce alla 1a barra pulita); regression-lock a pairs_sim. - PairsWorker: flat_skip + exit_ready + rilevamento flat da OHLC (1h byte-exact). - runner: fetch diretto dei timeframe sub-orari + override position_size per-sleeve. - validate_worker_pairs: replay worker == backtest a 15m (8452 vs 8453 trade). - _defs/build_everything: sleeve PR_ETHBTC_15M (mezza size, pos 0.10) -> PORT06 FULL 6.43->7.20, OOS 8.58->9.66, DD giu'. Rischio bilanciato col 1h. - smoke live: Cerbero serve candele 15m fresche; worker ticca. Diari docs/diary/2026-06-09-*. Caveat slippage: mezza size = blend-tilt prudente. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
121 lines
7.4 KiB
Python
121 lines
7.4 KiB
Python
"""Definizioni canoniche dei portafogli (tutti i tipi visti finora)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
from src.portfolio.base import Portfolio, SleeveSpec # noqa: E402
|
|
|
|
# Universo live tradabile (8 asset con feed Cerbero v2 + parquet). ROT02/TSM01 ci ruotano sopra.
|
|
UNIVERSE8 = ["ADA", "BNB", "BTC", "DOGE", "ETH", "LTC", "SOL", "XRP"]
|
|
|
|
# Edge minimo (solo live): salta i fade/dip il cui TP cade entro 1.5x il costo round-trip
|
|
# (perdenti garantiti in regime piatto). Neutro sul backtest storico (0 trade rimossi su
|
|
# MR01, +leggero su DIP01), protettivo dal vivo. Solo MR01/DIP01 leggono il param;
|
|
# MR02/MR07 lo ignorano (**params). Vedi docs/diary/2026-06-01-tp-min-edge.md.
|
|
MIN_TP_FRAC = 0.0015
|
|
|
|
# Filtro TREND (live, swap dal loss-guard Hurst il 2026-06-07): salta le fade quando il prezzo
|
|
# e' esteso oltre trend_max*ATR(14) dalla EMA(ema_long) — non si fada un trend/crollo esteso.
|
|
# E' la config che la ricerca EXIT-16 (2026-06-04) ha effettivamente promosso (entries
|
|
# trend-filtrate, niente hurst). Gate PORT06 sul path live (trendmax_port06_impact, 2026-06-07):
|
|
# TREND-ONLY domina la config hurst-only su TUTTE le metriche (FULL Sharpe 7.23->7.89,
|
|
# OOS Sharpe 9.35->9.91, OOS DD 1.68->1.20), plateau robusto su trend_max 2.5/3.0/3.5.
|
|
# Il loss-guard Hurst (validato 2026-06-02 sull'engine PRE-EXIT-16 con SL intrabar) e'
|
|
# RIDONDANTE-DANNOSO dopo EXIT-16: attacca lo stesso regime (trending) saltando ingressi che
|
|
# con EXIT-16 sono tornati vincenti; la combinazione hurst+trend over-filtra (meta' dei trade,
|
|
# FULL Sharpe 7.11). hurst_skip_mask resta disponibile in fade_base (param hurst_max).
|
|
# Vedi docs/diary/2026-06-07-trendmax-gate.md.
|
|
TREND_MAX = 3.0
|
|
EMA_LONG = 200
|
|
|
|
# EXIT-16 close-confirm SL (live, 2026-06-04): lo SL intrabar fisso veniva triggerato dai
|
|
# wick transitori (falsi negativi: l'overshoot che buca lo stop rientra — e' il movimento
|
|
# che la fade fada). Lo stop scatta solo se il CLOSE sfonda sl ∓ 0.5*ATR14. PORT06:
|
|
# FULL Sharpe 6.47->7.84 DD 4.10->2.60, OOS 8.82->10.06 DD 1.30->1.15 (gate del loss-guard
|
|
# superato con margine; 34 agenti, 3 verifiche avversariali + tail-risk: coda ~= base,
|
|
# esce nei crash veri tipo FTX). Vedi docs/diary/2026-06-04-exit-lab.md.
|
|
SL_CONFIRM_ATR = 0.5
|
|
|
|
|
|
# Override stop-largo su MR02/ETH (2026-06-09). Lo sleeve a DD piu' alto e peggior performer reale
|
|
# (whipsaw: fada un downtrend in long, poi shorta il rimbalzo). Ricerca 127 strategie + verifica
|
|
# avversariale + gate PORT06: nessun SOSTITUTO batte il live EXIT-16; la miglioria e' ALLARGARE lo
|
|
# stop (sl_atr 2.0->3.0) mantenendo il close-confirm. Cattura il beneficio del no-SL (gli stop di
|
|
# meta'-discesa sono falsi negativi) SENZA la coda da sl=0 (worst-trade -50% vs -65% del no-SL; la
|
|
# rete di catastrofe resta -> regola "mai sl=0" rispettata). Gate PORT06 (swap del solo MR02_ETH):
|
|
# FULL Sh 6.73->6.77 DD 3.67->3.30, OOS Sh 8.80->8.82 DD 1.23 (domina il live, FULL DD -0.37pp).
|
|
# Scoped a MR02/ETH: gli altri 5 fade (logica diversa) NON sono stati ri-gateati -> invariati.
|
|
# Diario docs/diary/2026-06-08-mr02eth-replace-search.md (addendum 2026-06-09).
|
|
SL_ATR_WIDE_MR02ETH = 3.0
|
|
|
|
|
|
def _fade_params(c: str, a: str) -> dict:
|
|
p = {"min_tp_frac": MIN_TP_FRAC, "trend_max": TREND_MAX,
|
|
"ema_long": EMA_LONG, "sl_confirm_atr": SL_CONFIRM_ATR}
|
|
if (c, a) == ("MR02", "ETH"):
|
|
p["sl_atr"] = SL_ATR_WIDE_MR02ETH
|
|
return p
|
|
|
|
|
|
FADE = [SleeveSpec(kind="single", name=c, sid=f"{c}_{a}", asset=a, cluster=f"{a}-rev",
|
|
params=_fade_params(c, a))
|
|
for a in ("BTC", "ETH") for c in ("MR01", "MR02", "MR07")]
|
|
HONEST = [
|
|
# DIP01: single-asset 1h -> StrategyWorker (Strategy DIP01_dip_buy). TR01/ROT02: multi-asset.
|
|
# EXIT-16 esteso a DIP01 (2026-06-07, sweep punto 9): gate dip01_exit16_impact.py con
|
|
# engine GAP-AWARE — grid 36/36 BTC e 35/36 ETH (train E oos), plateau buffer piatto,
|
|
# PORT06 FULL Sh 6.43->6.61 DD 3.96->3.58, OOS 8.58->8.77. Era l'unico sleeve BTC con
|
|
# esecuzione reale ancora sul branch SL intrabar wick-sensitive.
|
|
SleeveSpec(kind="single", name="DIP01", sid="DIP01_BTC", asset="BTC", cluster="BTC-rev",
|
|
params={"min_tp_frac": MIN_TP_FRAC, "sl_confirm_atr": SL_CONFIRM_ATR}),
|
|
SleeveSpec(kind="basket", name="TR01", sid="TR01_basket", cluster="trend",
|
|
params={"universe": ["BNB", "BTC", "DOGE", "SOL", "XRP"], "tf": "4h"}),
|
|
SleeveSpec(kind="rotation", name="ROT02", sid="ROT02_rot", cluster="rotation",
|
|
params={"universe": UNIVERSE8, "tf": "1d", "top_k": 3, "gross": 0.45}),
|
|
]
|
|
PAIRS = [
|
|
SleeveSpec(kind="pairs", name="PR01", sid="PR_ETHBTC", a="ETH", b="BTC", cluster="ETH-rev"),
|
|
# BLEND timeframe: ETH/BTC anche a 15m (flat-skip), accanto al 1h. Decorrelato 0.37 dal
|
|
# 1h -> diversificatore intra-pairs. Worker validato (validate_worker_pairs 15m, replay
|
|
# == pairs_sim_flat). Gate PORT06: docs/diary/2026-06-09-pairs15m-live-path.md.
|
|
SleeveSpec(kind="pairs", name="PR01", sid="PR_ETHBTC_15M", a="ETH", b="BTC", tf="15m",
|
|
params={"n": 66, "z_in": 1.674, "z_exit": 1.0, "max_bars": 35, "flat_skip": True,
|
|
"position_size": 0.10}, # meta' del family PAIRS (0.20): blend-tilt
|
|
cluster="ETH-rev"),
|
|
SleeveSpec(kind="pairs", name="PR01", sid="PR_LTCETH", a="LTC", b="ETH", cluster="ETH-rev"),
|
|
SleeveSpec(kind="pairs", name="PR01", sid="PR_ADAETH", a="ADA", b="ETH", cluster="ETH-rev"),
|
|
SleeveSpec(kind="pairs", name="PR01", sid="PR_BTCLTC", a="BTC", b="LTC", cluster="BTC-rev"),
|
|
SleeveSpec(kind="pairs", name="PR01", sid="PR_ETHSOL", a="ETH", b="SOL", cluster="ETH-rev"),
|
|
]
|
|
TSM = [SleeveSpec(kind="tsmom", name="TSM01", sid="TSM01", cluster="trend",
|
|
params={"universe": UNIVERSE8, "tf": "1d",
|
|
"horizons": [63, 126, 252], "thr": 1.0, "gross": 0.30})]
|
|
# SH01 live (punto-10, 2026-06-07): il runner passa la storia FULL (parquet+feed) e
|
|
# last_block_only fitta/predice solo l'ultimo blocco del walk-forward (segnali ==
|
|
# WF completo per costruzione). Il regime corto train-365g NON e' robusto (BTC
|
|
# negativo a fee 2x, trade-rate 22% vs 10% validato): sh01_trainwindow_validate.py.
|
|
SHAPE = [SleeveSpec(kind="ml", name="SH01", sid=f"SH_{a}", asset=a, cluster="shape",
|
|
params={"last_block_only": True})
|
|
for a in ("BTC", "ETH")]
|
|
|
|
PORTFOLIOS = {
|
|
"PORT01": Portfolio("PORT01", "Honest", HONEST, weighting="equal"),
|
|
"PORT02": Portfolio("PORT02", "Fade master", FADE, weighting="equal"),
|
|
"PORT03": Portfolio("PORT03", "Master", FADE + HONEST, weighting="equal"),
|
|
"PORT04": Portfolio("PORT04", "Master + pairs", FADE + HONEST + PAIRS,
|
|
weighting="cap", caps={"PAIRS": 0.33}),
|
|
"PORT05": Portfolio("PORT05", "Master esteso", FADE + HONEST + PAIRS + TSM,
|
|
weighting="cap", caps={"PAIRS": 0.33}),
|
|
# SHAPE cappata a ~mezzo sleeve equal (2026-06-05): SH01 non ha SL per design e la
|
|
# ricerca multi-agente (sh01_exit_lab, 11 famiglie di stop, 0 sopravvissute) dimostra
|
|
# che NESSUNO stop taglia la coda ETH senza rompere l'edge -> si dimezza l'esposizione
|
|
# (costo backtest ~0: FULL 6.47->6.43, OOS 8.82->8.58, FULL DD 4.10->3.96). Vedi
|
|
# docs/diary/2026-06-05-sh01-sl-research.md.
|
|
"PORT06": Portfolio("PORT06", "Master + shape", FADE + HONEST + PAIRS + TSM + SHAPE,
|
|
weighting="cap", caps={"PAIRS": 0.33, "SHAPE": 0.0588}, leverage=2.0),
|
|
}
|