feat(portfolio): expose corporate action and replay consolidation

This commit is contained in:
2026-09-13 13:47:46 +09:00
parent 7a45bec3cb
commit 77468631b1
2 changed files with 49 additions and 2 deletions
+22
View File
@@ -170,6 +170,17 @@ def calculate_realized_pnl(
if running_qty < 0:
running_qty = 0.0
elif side == "stock_consolidation":
before = float(row.get("quantity_before", running_qty))
after = float(row.get("quantity_after", row.get("asset_quantity_after", 0.0)))
if before <= 0 or after <= 0 or running_qty <= 0:
warning_triggered = True
continue
if abs(running_qty - before) > 1e-9:
warning_triggered = True
running_qty = after
running_wac = float(row.get("average_price_after", running_wac * before / after))
warning: str | None = None
if warning_triggered:
warning = (
@@ -252,6 +263,17 @@ def calculate_current_wac(rows: list[dict[str, Any]]) -> CurrentWacResult:
if running_qty < 0:
running_qty = 0.0
elif side == "stock_consolidation":
before = float(row.get("quantity_before", running_qty))
after = float(row.get("quantity_after", row.get("asset_quantity_after", 0.0)))
if before <= 0 or after <= 0 or running_qty <= 0:
warning_triggered = True
continue
if abs(running_qty - before) > 1e-9:
warning_triggered = True
running_qty = after
running_wac = float(row.get("average_price_after", running_wac * before / after))
warning: str | None = None
if warning_triggered:
warning = (