PnL SQL Interview Guide
PnL SQL interview guide for positions, trades, prices, realized and unrealized PnL, aggregation, examples, and caveats.
Candidates computing simple trading or portfolio metrics in SQL.
PnL needs position and price definitions
A PnL query must define trades, positions, valuation prices, and whether the metric is realized, unrealized, or total PnL.
Timing drives valuation
The price used for valuation should match the time or period being measured. Future prices create lookahead, while stale prices can misstate risk.
Concrete example
A simple mark-to-market query can aggregate position by symbol and multiply by the latest available price at the valuation timestamp.
Toy formulas have limits
Real PnL can involve fees, financing, corporate actions, multi-currency effects, and accounting rules. State the simplified assumption in interviews.
Common mistakes
Candidates often mix trade-time and valuation-time prices. Separate execution data from valuation data before computing PnL.
Practice the pattern
Use the LeetQuidity curriculum and calibration to turn this topic into a focused practice plan.