Design a Real-Time Position Tracker
Signal: Tests whether the candidate has thought about fills vs marks, average price, realized vs unrealized P&L. These differences cause real trading desk bugs.
Question
Design a class that tracks a long/short position across multiple fills, maintaining: net position, average entry price, realized P&L (from closed trades), and mark-to-market unrealized P&L given a current price. Be careful when positions flip sign.
What to watch for
- Candidate uses 'average price' to mean different things in different parts of the code.
- Candidate's logic breaks when a long position is flipped to short within a single fill.
- Strong signal: candidate distinguishes 'average cost' (weighted history of opens) from 'VWAP' (volume-weighted).