Market maker performance tracking at Optiver and Jump Trading requires real-time attribution of cash balances, FIFO inventory matching, and Mark-to-Market (MTM) PnL across rapid event streams.
Design an automated market maker accounting simulator MarketMakerSimulator that processes a chronological sequence of trade executions and mid-price updates.
Accounting Rules:
- Cash Accounting: A buy of volume V at price P reduces cash by P⋅V. A sell increases cash by P⋅V.
- FIFO Inventory Tranches: Inventory is matched on a First-In-First-Out (FIFO) basis. When holding long inventory, selling shares closes the oldest long tranche, realizing profit (Psell−Pbuy)⋅V. Conversely, when holding short inventory, buying shares covers the oldest short tranche, realizing profit (Pshort−Pbuy)⋅V.
- Mark-to-Market PnL: At any benchmark mid-price Pmid:
MTM PnL=Cash+(Inventory×Pmid)−Initial Cash
Your Task
Implement the MarketMakerSimulator class:
__init__(initial_cash: float = 0.0)
record_fill(timestamp: float, side: str, price: float, volume: int) -> None (side is 'buy' or 'sell')
update_mid_price(timestamp: float, mid_price: float) -> None
get_summary() -> dict returning {'cash': float, 'inventory': int, 'realized_pnl': float, 'unrealized_pnl': float, 'mtm_pnl': float}.
Constraints
- All prices >0.0, volumes ≥1.
- All calculations rounded to 4 decimal places in summary.