Daily Net Position Per Book From Raw Trade Fills

Last updated: November 29, 2026

Quick Overview

Given a fills table (fill_id, book, symbol, side, qty, fill_ts), write SQL that returns each book's end-of-day net position per symbol for every trading day, carrying positions forward on days with no fills.

D. E. Shaw
Data Manipulation (SQL/Python)
Data Engineer
D. E. Shaw
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given a fills table (fill_id, book, symbol, side, qty, fill_ts), write SQL that returns each book's end-of-day net position per symbol for every trading day, carrying positions forward on days with no fills.

Typical of a D. E. Shaw technical screen for data-focused engineers who feed research and risk systems with clean daily state. The interviewer checks window functions, correct sign handling for buys and sells, and whether you notice that days with no fills still need a row.

What the Interviewer Expects
  • Converts side to a signed quantity
  • Aggregates to per-day net change before taking a running sum
  • Builds a calendar so days without fills carry the prior position
  • Uses a window partitioned by book and symbol ordered by date
  • Considers time zones for what counts as a trading day
Key Topics to Cover
window functions
running totals
calendar joins
position keeping
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 seed positions that existed before the first fill in the table?
  • How do corporate actions such as a 2-for-1 split change this query?
  • How would you make this incremental instead of recomputing history nightly?
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

side is 'B' or 'S', qty is always positive, fill_ts is UTC. A trading day is the exchange local date (America/New_York for US equities). Assume a trading_days(d) table exists. Positions start ...

Approach

Step 1: sign the quantity and roll fills up to daily net change per (book, symbol, day). Step 2: cross join each (book, symbol) pair with the trading calendar from its first active day so quiet days e...


Submit Your Answer
Markdown supported

Related Questions