Daily Portfolio Turnover From Position Weight Snapshots
Last updated: November 29, 2026
Quick Overview
Given a table of end-of-day portfolio weights with one row per date and ticker (weight 0 when flat), write SQL that returns each day's one-way turnover and gross exposure.
Trexquant
November 29, 20260
0
0 solved
Given a table of end-of-day portfolio weights with one row per date and ticker (weight 0 when flat), write SQL that returns each day's one-way turnover and gross exposure.
Turnover drives transaction cost, so every simulated or live book at a systematic fund gets a daily turnover report. The interviewer checks window function fluency and whether you know the one-way convention (half the sum of absolute weight changes).
What the Interviewer Expects
- Uses LAG partitioned by ticker and ordered by date
- Computes 0.5 times the sum of absolute weight changes
- Excludes the first date where no prior weight exists
- Reports gross exposure alongside turnover for scale
- Explains why a dense table (zeros for flat names) matters
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 compute turnover if the table only stores non-zero positions?
- How would you convert turnover into an estimated daily cost in basis points?
- How would you flag days whose turnover is three times the trailing average?
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
positions(trade_date, ticker, weight) with weights as fractions of capital, long positive and short negative, and a row for every name in the universe each day. Turnover here means one-way: total tr...
Approach
For each ticker, pull the previous day's weight with LAG. The daily trade in a name is |w_t - w_{t-1}|. Sum across names, halve it, and group by date. The first date has no previous weight and is ...