14522262e6
Reset del progetto su fondamenta verificate dopo la scoperta che l'intera libreria "validata OOS" era artefatto di feed contaminato (print fantasma del feed Cerbero TESTNET + storico Binance/USDT). - Storico ricostruito da Deribit MAINNET (ccxt pubblico, tokenless) e CERTIFICATO (certify_feed.py): BTC/ETH puliti su TUTTA la storia (mediana 2-6 bps vs Coinbase USD), integrita' OHLC + coerenza resample (maxΔ 0.00) + cross-venue OK. Alt esclusi (illiquidi/divergenti: LTC/DOGE 50-82% barre flat; XRP/BNB non certificabili). - Verdetto sul feed pulito: FADE / PAIRS / XS01 / TSM01 morti (ogni portafoglio Sharpe -2.3..-3.0, DD ~40%); solo SH01 e frammenti HONEST con segnale residuo, da ri-validare in isolamento. - Cleanup "restart pulito": strategie, stack live (src/live, src/portfolio, runner/executor, yml, docker), ~100 script ricerca/gate, waste/games/ portfolios, dati non certificati + cache e 60+ diari -> archiviati in Old/ (preservati, non cancellati). Diario consolidato in un unico documento. - Skeleton ricerca tenuto: Strategy ABC + indicatori + src/fractal + src/backtest/engine + load_data; tool dati certificati (rebuild_history, certify_feed, audit_feed, multi_source_check). - Universo dati ATTIVO: solo BTC/ETH (5m/15m/1h); guardrail fisico (load_data su alt -> FileNotFoundError). Esecuzione DISABILITATA, conto flat. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
"""Helper condivisi sulle barre OHLCV live (lezione EXIT-16, 2026-06-05).
|
|
|
|
La riga -1 di un df di candele e' la candela IN FORMAZIONE finche' non e'
|
|
trascorsa la sua durata: valutare segnali/exit-confirm su quella riga
|
|
reintroduce la wick-sensitivity che EXIT-16 elimina (audit live: 2 stop su 3
|
|
del crash ETH erano wick-stop sulla barra in corso). Questa e' l'UNICA
|
|
implementazione della detection — prima era copiata in 4 punti
|
|
(strategy_worker, basket_trend_worker, pairs_worker, runner._check_stale_feed)
|
|
con una variante hardcoded a 1h: una correzione applicata a una copia e
|
|
dimenticata nelle altre reintrodurrebbe il bug in silenzio.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
|
|
import numpy as np
|
|
|
|
|
|
def bar_ms_of(ts_ms, window: int = 50) -> int:
|
|
"""Durata stimata della barra: mediana dei diff degli ultimi `window`
|
|
timestamp (ms). 0 se la serie e' troppo corta per stimarla."""
|
|
ts = np.asarray(ts_ms, dtype="int64")
|
|
if len(ts) < 2:
|
|
return 0
|
|
return int(np.median(np.diff(ts[-window:])))
|
|
|
|
|
|
def last_bar_is_forming(ts_ms, now_ms: int | None = None) -> bool:
|
|
"""True se la riga -1 e' la candela IN CORSO (now < ts[-1] + durata barra)."""
|
|
ts = np.asarray(ts_ms, dtype="int64")
|
|
if len(ts) == 0:
|
|
return False
|
|
bar = bar_ms_of(ts)
|
|
if not bar:
|
|
return False
|
|
if now_ms is None:
|
|
now_ms = int(time.time() * 1000)
|
|
return now_ms < int(ts[-1]) + bar
|
|
|
|
|
|
def last_settled_idx(ts_ms, now_ms: int | None = None) -> int:
|
|
"""Indice dell'ultima barra COMPLETATA: -1 se la riga -1 e' chiusa,
|
|
-2 se e' in formazione."""
|
|
return -2 if last_bar_is_forming(ts_ms, now_ms) else -1
|