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),