feat(live): INIT_LINEAGE — eredita' capitale al cambio timeframe + sweep migliorie serale

Worker nuovo (no status.json) eredita capital/real_capital dal gemello piu'
recente stessa strategia+asset (mai la posizione): niente piu' seed manuale
al prossimo swap. 3 test nuovi, suite 129 passed.
Ricerca: gate 10m ADD bocciato (OOS Sh 10.86->10.76, watchlist chiusa);
XSEC breadth 8->14 Deribit BOCCIATO (gambe flat 91-99% corrompono il ranking)
ma promettente su dati HL reali (-6%->+9% stessa finestra) -> sblocco = routing
dati Hyperliquid quando la storia sara' sufficiente.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Adriano Dal Pastro
2026-06-12 21:18:30 +00:00
parent 12e71d4c8b
commit 643ff7f943
3 changed files with 131 additions and 1 deletions
+31 -1
View File
@@ -114,10 +114,40 @@ class StrategyWorker:
self._load_state()
self._save_state()
def _inherit_lineage_capital(self):
"""Al primo avvio (nessun status.json) eredita capital/real_capital dal
worker piu' recente di STESSA strategia+asset su altro timeframe (lineage).
Nato dallo swap fade 1h->15m (2026-06-12): i worker nuovi partivano
dall'allocazione del pool scartando il PnL accumulato dal gemello 1h
(-16.8 di equity fantasma, riallineata a mano). Eredita SOLO i ledger,
MAI la posizione (quella appartiene al worker vecchio)."""
try:
stem = f"{self.strategy.name}__{self.asset}__"
siblings = [d for d in self.work_dir.parent.glob(f"{stem}*")
if d.is_dir() and d.name != self.worker_id
and (d / "status.json").exists()]
if not siblings:
return
latest = max(siblings, key=lambda d: (d / "status.json").stat().st_mtime)
with open(latest / "status.json") as f:
old = json.load(f)
if old.get("capital") is not None:
self.capital = float(old["capital"])
if old.get("real_capital") is not None:
self.real_capital = float(old["real_capital"])
self._log("INIT_LINEAGE", {"da": latest.name,
"capital": round(self.capital, 2),
"real_capital": round(self.real_capital, 2)})
except Exception as e: # mai bloccare il boot per il lineage
print(f" [{self.worker_id}] WARN lineage: {e}")
def _load_state(self):
"""Riprende stato da status.json se esiste."""
if not self.status_path.exists():
self._log("INIT", {"capital": self.capital, "strategy": self.strategy.name,
self._inherit_lineage_capital()
self._log("INIT", {"capital": round(self.capital, 2),
"real_capital": round(self.real_capital, 2),
"strategy": self.strategy.name,
"asset": self.asset, "tf": self.tf})
return