fix(trader): record trade and snapshot prices at full precision

Rounding to cents made trade logs irreproducible for low-priced lines
(HK ETFs in USD, A-shares): replaying a log drifted up to $200 from the
recorded cash.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-25 02:05:15 +08:00
parent 592de02e27
commit 10a74ea4f7

View File

@@ -523,7 +523,7 @@ def compute_trades(holdings: dict, cash: float, target_weights: dict,
"shares_delta": int(round(delta)) if integer_shares else round(delta, 4),
"direction": "BUY" if delta > 0 else "SELL",
"est_value": round(trade_value, 2),
"price": round(price, 2),
"price": round(price, 6),
"target_shares": int(round(target_shares)) if integer_shares else round(target_shares, 4),
"current_shares": int(current_shares) if integer_shares else round(current_shares, 4),
})
@@ -620,7 +620,7 @@ def execute_trades(state: dict, trades: list[dict], prices: dict,
"action": "BUY" if delta > 0 else "SELL",
"ticker": ticker,
"shares": abs(delta) if integer_shares else round(abs(delta), 4),
"price": round(price, 2),
"price": round(price, 6),
"value": round(cost, 2),
"commission": round(commission, 2),
})
@@ -650,7 +650,7 @@ def record_daily_snapshot(state: dict, date_str: str, prices: dict,
p = prices.get(ticker, 0.0)
positions[ticker] = {
"shares": shares,
"price": round(p, 2),
"price": round(p, 6),
"value": round(shares * p, 2),
}
@@ -662,7 +662,7 @@ def record_daily_snapshot(state: dict, date_str: str, prices: dict,
"action": t["direction"],
"ticker": t["ticker"],
"shares": abs(t["shares_delta"]),
"price": round(p, 2),
"price": round(p, 6),
"value": round(abs(t["shares_delta"]) * p, 2),
})