SQL Slippage Versus Arrival Price by Execution Algorithm
Last updated: November 29, 2026
Quick Overview
Given an orders table (order id, algo, side, order quantity, arrival mid) and a fills table (order id, fill quantity, fill price), write SQL that reports, per algorithm, the order count, notional-weighted and simple average slippage versus arrival in basis points (positive meaning cost), and the fill rate.
Virtu Financial
November 29, 20260
0
0 solved
Given an orders table (order id, algo, side, order quantity, arrival mid) and a fills table (order id, fill quantity, fill price), write SQL that reports, per algorithm, the order count, notional-weighted and simple average slippage versus arrival in basis points (positive meaning cost), and the fill rate.
Comparing agency algorithms on implementation shortfall is a daily task for Virtu's execution services and analytics teams. The interviewer checks side-aware sign conventions, aggregation at the right grain before averaging, and not dropping unfilled orders from the fill rate.
What the Interviewer Expects
- Aggregate fills to one row per order before joining
- Apply the side sign so cost is positive for both buys and sells
- Express slippage in basis points of arrival mid
- Weight by filled notional and also show the simple mean
- Keep unfilled orders for fill rate with a LEFT JOIN
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 add opportunity cost for the unfilled shares?
- How would you test whether one algo is significantly cheaper than another?
- How would you control for order size as a percent of ADV?
- What changes if arrival mid is missing for some orders?
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
One row per parent order in orders; many rows per order in fills. side is 'BUY' or 'SELL'. Arrival mid is the NBBO midpoint when the order reached the algo. Some orders may have no fills....
Approach
First collapse fills to filled quantity and average fill price per order. Then compute per-order slippage: sign * (avg_fill - arrival_mid) / arrival_mid * 10,000, where sign is +1 for buys and -1 for ...