Measure Daily Portfolio Turnover From a Weights Panel
Last updated: November 29, 2026
Quick Overview
Given a pandas DataFrame of daily portfolio weights (dates by tickers, possibly with missing entries), compute daily turnover as the sum of absolute weight changes after scaling each day to unit gross exposure, and the average turnover.
Worldquant
November 29, 20260
0
0 solved
Given a pandas DataFrame of daily portfolio weights (dates by tickers, possibly with missing entries), compute daily turnover as the sum of absolute weight changes after scaling each day to unit gross exposure, and the average turnover.
Turnover is one of the headline statistics reported next to Sharpe for every simulated alpha, and it drives transaction cost estimates. A data engineer at WorldQuant needs to compute it correctly on panels where instruments enter and leave the universe.
What the Interviewer Expects
- Treats a missing weight as a zero position
- Normalizes each day to unit gross before differencing
- Uses diff along the date axis after sorting the index
- Leaves the first day undefined rather than counting the initial build as turnover
- Explains how the result feeds a cost model
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 define turnover if the book size changes from day to day?
- How would you compute this for 5,000 instruments and 20 years without loading it all into memory?
- How does a decay operator on the alpha affect this number?
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
Index is trading date, columns are tickers, values are signed weights (long positive, short negative). Missing means the instrument is not held. Weights may not be normalized, so scale each day so tha...
Approach
Sort by date, fill missing with 0, divide each row by its gross, then take the row-wise diff, absolute value, and row sum. A day with zero gross stays at zero weights. The first day has no previous da...