From 61fcc29c5bd372d819d989ac0cde696ddd8d6074 Mon Sep 17 00:00:00 2001 From: Adriano Dal Pastro Date: Wed, 10 Jun 2026 21:23:52 +0000 Subject: [PATCH] =?UTF-8?q?fix(xsec):=20cast=20numpy->Python=20in=20=5Fsav?= =?UTF-8?q?e/=5Fclose=5Fbook=20=E2=80=94=20int64=20rompeva=20json.dumps=20?= =?UTF-8?q?e=20bloccava=20il=20runner=20in=20error-streak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- src/live/xsec_worker.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/live/xsec_worker.py b/src/live/xsec_worker.py index a8eb5e1..349026a 100644 --- a/src/live/xsec_worker.py +++ b/src/live/xsec_worker.py @@ -67,11 +67,13 @@ class CrossSectionalWorker: def _save(self): self.status_path.write_text(json.dumps({ - "capital": round(self.capital, 2), "in_position": self.in_position, - "weights": {a: round(v, 5) for a, v in self.weights.items()}, - "entry_px": self.entry_px, "bars_held": self.bars_held, "cooldown": self.cooldown, - "total_trades": self.total_trades, "total_wins": self.total_wins, - "last_bar_ts": self.last_bar_ts, "last_update": datetime.now(timezone.utc).isoformat(), + "capital": round(float(self.capital), 2), "in_position": bool(self.in_position), + "weights": {a: round(float(v), 5) for a, v in self.weights.items()}, + "entry_px": {a: float(v) for a, v in self.entry_px.items()}, + "bars_held": int(self.bars_held), "cooldown": int(self.cooldown), + "total_trades": int(self.total_trades), "total_wins": int(self.total_wins), + "last_bar_ts": int(self.last_bar_ts), + "last_update": datetime.now(timezone.utc).isoformat(), }, indent=2)) def _log(self, event, data=None): @@ -113,11 +115,12 @@ class CrossSectionalWorker: book = 0.0 for k, a in enumerate(self.universe): book += self.weights[a] * np.log(closes_now[k] / self.entry_px[a]) - net = book - 2 * self.fee_rt - pnl = self.capital * self.position_size * self.leverage * net + # cast a tipi Python: i numpy (float64/int64/bool_) rompono json.dumps in _save + net = float(book - 2 * self.fee_rt) + pnl = float(self.capital * self.position_size * self.leverage * net) self.capital = max(self.capital + pnl, 10.0) self.total_trades += 1 - self.total_wins += net > 0 + self.total_wins += 1 if net > 0 else 0 acc = self.total_wins / self.total_trades * 100 if self.total_trades else 0 self._log("CLOSE", {"book_ret": round(book * 100, 3), "net": round(net * 100, 3), "pnl": round(pnl, 2), "capital": round(self.capital, 2),