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
Data Manipulation (SQL/Python)
Data Engineer
Deutsche Bank
November 29, 2026
Data Engineer
Onsite
Data Manipulation (SQL/Python)
Medium

0

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
Window functions
LAG
Running totals
PnL attribution
Date spines
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. 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 Problems
Sample 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
  1. Sign quantities and aggregate fills per trader, instrument and day into net_qty and cash_out = ∑qipi\sum q_i p_i.
  2. Build a grid from each pair's first trade date across all mark dates so days wi...

Submit Your Answer
Markdown supported

Related Questions