As-Of Join Fills to Prevailing Quotes to Measure Slippage
Last updated: November 29, 2026
Quick Overview
Given a fills table and a quotes table, attach to each fill the latest quote for the same symbol at or before the fill time (rejecting quotes older than one second), then report average slippage versus mid in basis points by pod and side.
Millennium
November 29, 20260
0
0 solved
Given a fills table and a quotes table, attach to each fill the latest quote for the same symbol at or before the fill time (rejecting quotes older than one second), then report average slippage versus mid in basis points by pod and side.
Transaction cost analysis is how pods and the central execution team at a multi-strategy fund judge brokers and algos, and it hinges on the as-of join. The interviewer checks that you can express it in SQL without a cross join, handle stale or missing quotes and sign slippage correctly for buys and sells.
What the Interviewer Expects
- Uses a lateral subquery or window technique to get the latest quote at or before each fill
- Applies a staleness cutoff and keeps unmatched fills visible
- Signs slippage so positive always means cost for both buys and sells
- Weights by notional where appropriate
- Mentions indexes on (symbol, ts) for performance
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 do this in pandas with merge_asof?
- What if the quote and fill clocks come from different venues with skew?
- How would you compare against arrival price instead of the prevailing mid?
- How would you scale this to a full day of US equities quotes?
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(fill_id, pod, symbol, side, ts, price, qty) with side 'B' or 'S'. quotes(symbol, ts, bid, ask) with many rows per symbol per second. Mid is (bid + ask) / 2. Slippage bps = `side_sign * (pr...
Approach
For each fill, pick the single quote row with the largest ts <= fill.ts for that symbol. A LEFT JOIN LATERAL ... ORDER BY ts DESC LIMIT 1 does this with an index seek per fill. Then drop quotes ol...