Measure Execution Slippage With an As-Of Join to Quotes

Last updated: November 29, 2026

Quick Overview

Given a fills table and a quotes table, compute each fill's slippage in basis points versus the prevailing mid price just before the fill, and report quantity-weighted slippage per symbol along with fills that had no recent quote.

Balyasny
Data Manipulation (SQL/Python)
Data Engineer
Balyasny
November 29, 2026
Data Engineer
Take-home Project
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given a fills table and a quotes table, compute each fill's slippage in basis points versus the prevailing mid price just before the fill, and report quantity-weighted slippage per symbol along with fills that had no recent quote.

Transaction cost analysis tells Balyasny's PMs and Execution Technology whether algorithms and brokers are leaking alpha. The take-home checks point-in-time joins, sign conventions for buys and sells, and honest handling of stale or missing quotes.

What the Interviewer Expects
  • Use an as-of (backward) join by symbol rather than an exact timestamp join
  • Exclude the quote with the identical timestamp to avoid using a quote caused by the fill
  • Apply a tolerance so a stale quote is not treated as prevailing
  • Sign slippage so positive always means worse than mid for both sides
  • Weight by quantity and report unmatched fills explicitly
Key Topics to Cover
merge_asof
transaction cost analysis
point-in-time joins
pandas
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 measure slippage versus arrival price of the parent order instead of the fill-time mid?
  • How would you do this as-of join in SQL on a warehouse that lacks ASOF JOIN?
  • How should you handle fills in auctions where there is no continuous quote?
  • 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 Problems
Sample Answer
Clarify the Data

fills(ts, symbol, side, price, qty) with side 'B' or 'S'; quotes(ts, symbol, bid, ask) as top-of-book updates. Timestamps are on the same clock (ask about exchange versus capture time). Slippage f...

Approach

Sort both frames by time, merge_asof backward by symbol with allow_exact_matches=False and a 2 second tolerance, compute mid and signed slippage, then aggregate quantity-weighted slippage per symb...


Submit Your Answer
Markdown supported

Related Questions