audit+fix: anti-look-ahead audit, migrate deployable config to >=12h
- trackD_lookahead_audit.py: relabel test (left==right, no labeling leak) + execution-lag stress -> our trend pipeline is CLEAN (4h Sharpe 1.36 robust to +1 bar lag, label-invariant) - ADOPT conservative conclusion: deploy at 12h (sub-12h: costs/overfit dominate, slight Sharpe bump unreliable). 12h: Sharpe 1.32, DD 13.3%, CAGR 16.2% ~ identical and robust - trend_portfolio: DEPLOY_TF=12h, resample_tf(rule); paper trader + tests on 12h - calendar research (NEGATIVE, both): trackF seasonality (spurious), trackG prior-levels (breakouts continue, fade dead; only long-drift survivor, redundant with TP01) - gitignore data/paper_trend runtime state
This commit is contained in:
@@ -4,13 +4,16 @@ Vincitrice della ricerca su dati certificati BTC/ETH (Deribit mainnet). TSMOM mu
|
||||
(1-3-6 mesi) vol-targeted, portafoglio 50/50 BTC+ETH. Validata onestamente (no look-ahead,
|
||||
fee 0.10% RT, positiva ogni anno 2019-2026, robusta su griglia e su tutti i timeframe 15m-1d).
|
||||
|
||||
Config canonica deployabile (PORT LF4h):
|
||||
timeframe 4h, LONG-FLAT (niente short), vol-target 20%, leverage cap 2x.
|
||||
-> CAGR ~16.6%, Sharpe ~1.32, maxDD ~12.3% (backtest 2019-2026 su 50/50 BTC+ETH).
|
||||
Config canonica deployabile (PORT LF12h):
|
||||
timeframe 12h, LONG-FLAT (niente short), vol-target 20%, leverage cap 2x.
|
||||
-> CAGR ~16.2%, Sharpe ~1.32, maxDD ~13.3% (backtest 2019-2026 su 50/50 BTC+ETH).
|
||||
|
||||
Perche' long-flat e 4h: gli short del trend rendono meno e aggiungono DD; il 4h e' il punto
|
||||
dolce (meno rumore/fee del 15m, meno lag dell'1d). Vedi docs/diary/2026-06-19-research-synthesis.md
|
||||
e scripts/research/trackD_*.py.
|
||||
Perche' >=12h (AGGIORNATO 2026-06-19): l'audit anti-look-ahead (scripts/research/
|
||||
trackD_lookahead_audit.py) mostra che il pipeline e' pulito (label-invariante, robusto a +1
|
||||
barra di lag), ma SOTTO le 12h costi e overfitting al rumore ad alta frequenza dominano (il
|
||||
piccolo extra di Sharpe a 4h/6h/8h non e' affidabile). A 12h/1d il risultato e' ~identico e
|
||||
robusto -> si deploya a 12h. Perche' long-flat: gli short del trend rendono meno e aggiungono
|
||||
DD. Vedi docs/diary/2026-06-19-research-synthesis.md e scripts/research/trackD_*.py.
|
||||
|
||||
API (tutto causale, decide con dati <= close[i]):
|
||||
from src.strategies.trend_portfolio import TrendPortfolio, CANONICAL
|
||||
@@ -168,16 +171,26 @@ def _bars_per_year(idx: pd.DatetimeIndex) -> float:
|
||||
return 86400 * 365.25 / dt if dt and dt > 0 else 365.25
|
||||
|
||||
|
||||
def resample_4h(df_1h: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Resample 1h -> 4h (confini 00:00 UTC). Schema con 'datetime'."""
|
||||
DEPLOY_TF = "12h" # timeframe deployabile (>=12h: sotto, costi/overfit dominano)
|
||||
|
||||
|
||||
def resample_tf(df_1h: pd.DataFrame, rule: str = "12h") -> pd.DataFrame:
|
||||
"""Resample 1h -> rule (confini 00:00 UTC, open-labeled). Schema con 'datetime'.
|
||||
Il consumo e' index-based con shift +1 barra (net_returns) -> il labeling NON leakka
|
||||
(verificato in trackD_lookahead_audit.py: Sharpe left == Sharpe right)."""
|
||||
g = df_1h.copy()
|
||||
idx = pd.to_datetime(g["timestamp"], unit="ms", utc=True)
|
||||
idx.name = "dt"
|
||||
g.index = idx
|
||||
out = g.resample("4h", label="left", closed="left").agg(
|
||||
out = g.resample(rule, label="left", closed="left").agg(
|
||||
{"open": "first", "high": "max", "low": "min", "close": "last", "volume": "sum"})
|
||||
out = out.dropna(subset=["open"])
|
||||
out["datetime"] = out.index
|
||||
epoch = pd.Timestamp("1970-01-01", tz="UTC")
|
||||
out["timestamp"] = ((out.index - epoch) // pd.Timedelta(milliseconds=1)).astype("int64")
|
||||
return out.reset_index(drop=True)[["timestamp", "open", "high", "low", "close", "volume", "datetime"]]
|
||||
|
||||
|
||||
def resample_4h(df_1h: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Compat per gli script di ricerca. Per il DEPLOY usare resample_tf(df, '12h')."""
|
||||
return resample_tf(df_1h, "4h")
|
||||
|
||||
Reference in New Issue
Block a user