Measure Fill Markouts by Exchange at Several Time Horizons

Last updated: November 29, 2026

Quick Overview

Given a fills table (fill_id, series_id, exchange, side, qty, price, ts_ms) and a quotes table of mid prices (series_id, ts_ms, mid), write SQL that computes total and per-contract markout PnL for each exchange at 100 ms, 1 s and 10 s after each fill, using the latest mid at or before each horizon.

Chicago Trading Company
Data Manipulation (SQL/Python)
Data Engineer
Chicago Trading Company
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given a fills table (fill_id, series_id, exchange, side, qty, price, ts_ms) and a quotes table of mid prices (series_id, ts_ms, mid), write SQL that computes total and per-contract markout PnL for each exchange at 100 ms, 1 s and 10 s after each fill, using the latest mid at or before each horizon.

Markouts are how a market maker measures adverse selection: if prices move against you right after you trade, your quotes are being picked off. CTC's research and data teams compute these across venues and horizons daily. The interviewer checks as-of join logic, sign conventions, and awareness of the volume of quote data involved.

What the Interviewer Expects
  • Uses an as-of lookup (latest quote at or before fill time plus horizon)
  • Signs markout so positive means the trade made money for us
  • Applies the 100 contract multiplier and quantity weighting
  • Expands each fill across horizons with a cross join
  • Excludes or flags fills with no quote available
  • Notes that a correlated subquery is slow at scale and names an ASOF JOIN alternative
Key Topics to Cover
as-of join
markouts
adverse selection
window lookups
time series SQL
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 write this with an ASOF JOIN in ClickHouse, kdb+ or DuckDB?
  • Should markouts use mid, microprice or the theoretical value? What changes in the conclusions?
  • How would you separate adverse selection from the half-spread you earned at the fill?
  • Quotes for all options series are billions of rows a day. How do you partition the data?
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

side is our side: 'B' means we bought. price is per share of an option with a 100 multiplier. quotes has one row per mid change per series, so the mid at time t is the last row with ts_ms <= t...

Approach

Cross join fills with a small horizons table so each fill appears once per horizon. For each pair, look up the latest mid at or before ts_ms + h_ms for that series. Then aggregate by exchange and ho...


Submit Your Answer
Markdown supported

Related Questions