Compute FIFO Realized PnL Across Option Position Flips
Last updated: November 29, 2026
Quick Overview
Given a time-ordered list of fills (signed quantity, price) for one option contract with a 100 multiplier, compute realized PnL using FIFO lot matching, the final net position, and the remaining open lots, correctly handling fills that close a position and open the opposite side.
Chicago Trading Company
November 29, 20260
0
0 solved
Given a time-ordered list of fills (signed quantity, price) for one option contract with a 100 multiplier, compute realized PnL using FIFO lot matching, the final net position, and the remaining open lots, correctly handling fills that close a position and open the opposite side.
Trade capture and position keeping are core systems at a market maker, and PnL that is off by a lot or a sign is an immediate escalation with traders. The interviewer checks lot-matching logic, sign conventions, and the flip case where one sell both closes a long and opens a short.
What the Interviewer Expects
- Uses a FIFO queue of open lots that all share one sign
- Matches against the oldest lot first and splits partially consumed lots
- Gets the sign right for closing longs versus closing shorts
- Handles a fill that flattens and then flips the position
- Applies the contract multiplier once, consistently
- Mentions integer or decimal prices for real money
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would the answer differ under average-cost accounting, and when would a desk prefer it?
- How would you add unrealized PnL marked to the current mid?
- Fills can arrive late or be busted by the exchange. How do you support corrections?
- How would you scale this to every option series the firm trades in real time?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Fills are (qty, price) with positive qty for buys and negative for sells, in time order. Realized PnL is generated only when a fill reduces existing exposure. Output `(realized, position, open_lots)...
High-Level Design
Invariant: the queue of open lots is either empty or all lots have the same sign as the net position. For each incoming fill, while it has the opposite sign of the front lot, match min(|qty|, |lot|)...