fix(portfolio): tolerate consolidation WAC residue
This commit is contained in:
@@ -19,6 +19,24 @@ def test_buy_consolidation_sell_replays_wac_and_realized_pnl():
|
||||
assert result.total_realized_pnl == 100
|
||||
|
||||
|
||||
def test_consolidation_replay_uses_preserved_total_cost_basis():
|
||||
rows = [
|
||||
{"side": "buy", "quantity": 1452, "price": 1086.2341459366393, "fee_amount": 0, "executed_at": datetime(2026, 9, 9, tzinfo=UTC)},
|
||||
{
|
||||
"side": "stock_consolidation",
|
||||
"quantity_before": 1452,
|
||||
"quantity_after": 726,
|
||||
"average_price_after": Decimal("2172.46829187"),
|
||||
"total_cost_basis": Decimal("1577211.97990000"),
|
||||
"executed_at": datetime(2026, 9, 10, tzinfo=UTC),
|
||||
},
|
||||
]
|
||||
|
||||
result = calculate_current_wac(rows)
|
||||
assert result.current_quantity == 726
|
||||
assert result.current_wac == float(Decimal("1577211.97990000") / Decimal(726))
|
||||
|
||||
|
||||
def test_canonical_hash_same_payload_and_changed_payload_differ():
|
||||
a = CorporateActionRequest(effective_date=date(2026, 1, 2), quantity_before=Decimal(10), quantity_after=Decimal(5), evidence_ref="ev")
|
||||
b = CorporateActionRequest(effective_date=date(2026, 1, 2), quantity_before=Decimal(10), quantity_after=Decimal(4), evidence_ref="ev")
|
||||
|
||||
Reference in New Issue
Block a user