Daily Trader PnL From Fills and End-of-Day Marks
Last updated: November 29, 2026
Quick Overview
Using a fills table (trader, instrument, side, quantity, price, timestamp) and an end-of-day marks table (instrument, date, close price), write SQL that returns each trader's daily mark-to-market PnL, split into carry PnL on positions held overnight and PnL on new trades.
Deutsche Bank
November 29, 20260
0
0 solved
Using a fills table (trader, instrument, side, quantity, price, timestamp) and an end-of-day marks table (instrument, date, close price), write SQL that returns each trader's daily mark-to-market PnL, split into carry PnL on positions held overnight and PnL on new trades.
Product control and front-office data teams at Deutsche Bank explain daily PnL by desk and trader, and the split between existing positions and new trades is a standard part of PnL attribution. This onsite SQL question tests window functions, building a date grid so days without trades still get carry PnL, and getting signs right.
What the Interviewer Expects
- Sign quantities by side
- Build a per-instrument day grid so non-trading days still carry PnL
- Compute running positions with a window SUM
- Use LAG on marks for carry PnL
- Verify that cumulative PnL equals realised plus unrealised from first principles
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you add realised versus unrealised PnL using FIFO lots?
- Instruments trade in different currencies: where does FX translation go?
- Fills can be booked late, after the day's PnL was signed off: how do you handle restatements?
- How would you check this against the official PnL from the risk system?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
fills(trader_id, isin, side, qty, price, fill_ts) with side BUY or SELL and positive qty. eod_marks(isin, mark_date, close_price) has one row per instrument per business day. Assume one currency a...
Approach
- Sign quantities and aggregate fills per trader, instrument and day into
net_qtyandcash_out= . - Build a grid from each pair's first trade date across all mark dates so days wi...