Objective
Turn "it is good to be at the front of the queue" into numbers: compute the probability that a resting limit order is filled given the orders ahead of it, check it by simulation, and show why a fill at the back of a queue is worse news than a fill at the front. This is the core of passive execution and of market making in large-tick products, where queues are long and the spread is almost always one tick.
Intuition
A bid resting at the best price earns the half-spread if it is filled. Two things can happen first: the orders ahead of you are consumed or cancelled and a market sell reaches you (a fill), or the price moves up away from you (no fill, and you missed the move). Your position in the queue sets how long you wait, and so how likely the price is to leave without you.
Then there is the sting: the fills you do get are not a random sample. A sell order large enough to reach the back of the queue is often part of a selling wave that will clear the level and push the price down. Conditional on being filled, the price is more likely to move against you, and more so the further back you were.
A fill-probability model
Measure the queue in lots of equal size. You rest at the best bid with lots ahead of you. Treat events as independent exponential clocks:
- market sells hit the bid at rate (one lot each), consuming the front of the queue;
- each lot ahead of you cancels at rate (lots behind you do not matter until you are filled);
- the price moves away (the ask side clears and the market ticks up, stranding your bid) at rate .
With lots ahead, the queue in front of you shrinks at rate and the race is lost at rate . Each step is won with probability , and the last step (a market sell reaching you, since you will not cancel yourself) with probability . The memoryless property makes the steps independent, so
Read it off: each extra lot ahead multiplies the fill probability by a factor below one, so decays roughly geometrically in queue position. Cancellations help (they shorten the queue for free), and help more when the queue is long. With no cancellations it is simply .
This is a deliberately simple model. Real queues have random order sizes, arrival rates that depend on the state of the book, cancellations concentrated at the back of the queue (recent joiners cancel most) and price moves that depend on the queue sizes themselves. The structure, a race between depletion and price moves, survives all of those refinements.
Worked example
fill probabilities, by formula and by simulation
Market sells arrive at per second, each lot ahead cancels at per second (an average resting life of 20 seconds) and the price moves away at per second. Compute the fill probability with 0, 5, 10, 20 and 40 lots ahead, and confirm by simulation.
Show solutionHide solution
At the front (): . With one lot ahead, multiply by ; with ten, the factors run from 0.913 up to . The simulation below draws each event from the competing exponential clocks.
import random
def fill_prob(n, mu, theta, kappa):
"""Probability a resting order with n lots ahead is filled before the price moves away."""
p = mu / (mu + kappa) # last step: a market order reaches you
for k in range(1, n + 1):
p *= (mu + k * theta) / (mu + k * theta + kappa) # one lot ahead leaves the queue
return p
def simulate(n, mu, theta, kappa, trials=100_000, seed=7):
rng = random.Random(seed)
fills, wait = 0, 0.0
for _ in range(trials):
ahead, t = n, 0.0
while True:
down = mu + ahead * theta # rate at which the queue ahead shrinks (or you get hit)
t += rng.expovariate(down + kappa)
if rng.random() < kappa / (down + kappa):
break # price moved away: no fill
if ahead == 0:
fills += 1
wait += t
break
ahead -= 1
return fills / trials, wait / max(fills, 1)
mu, theta, kappa = 1.0, 0.05, 0.1
for n in (0, 5, 10, 20, 40):
sim, w = simulate(n, mu, theta, kappa)
print(f"{n:>3} ahead: formula {fill_prob(n, mu, theta, kappa):.3f} simulated {sim:.3f} mean wait if filled {w:.1f}s")
Output:
0 ahead: formula 0.909 simulated 0.910 mean wait if filled 0.9s
5 ahead: formula 0.598 simulated 0.601 mean wait if filled 4.9s
10 ahead: formula 0.423 simulated 0.423 mean wait if filled 8.3s
20 ahead: formula 0.244 simulated 0.246 mean wait if filled 13.6s
40 ahead: formula 0.111 simulated 0.110 mean wait if filled 21.3s
Two things to notice. Going from the front to 10 lots back more than halves the fill probability. And the conditional waiting time grows much more slowly than the queue: with 40 ahead, the fills that do happen take 21 seconds, not the 41 that market orders alone would need, because cancellations do much of the work and because the fills that survive are the paths where depletion happened quickly. That last point is selection, and it is the root of adverse selection.
Adverse selection conditional on a fill
Suppose your bid has just been filled, with lots still behind you at the bid and lots at the ask. Take a one-tick spread and assume that whichever queue empties first moves the market by a full tick: if the bid clears, the new ask is the old bid; if the ask clears, the new bid is the old ask.
Model each queue size as an independent driftless random walk (orders join, cancel and get hit). Starting from , the probability that the bid empties first is a classical harmonic-measure result for Brownian motion in a quadrant:
It equals when the queues are equal and tends to 1 as . Mark your fill to the mid after the next price change. You bought at the bid, which is half a tick below the mid:
- price moves down: the new mid is half a tick below your price, a loss of 0.5 ticks;
- price moves up: the new mid is 1.5 ticks above your price.
So the expected mark-out is ticks, which is the half-spread (0.5) only when .
| Lots behind you () | Simulated | Mark-out (ticks) | |
|---|---|---|---|
| 1 | 0.937 | 0.937 | |
| 3 | 0.814 | 0.814 | |
| 10 | 0.500 | 0.499 | |
| 30 | 0.205 | 0.204 |
The simulated column runs the discrete version (each event picks a queue at random and moves it up or down one lot) 20,000 times per row. A fill with little left behind you means the bid is nearly exhausted: the next move is very likely down, and the half-spread you thought you earned is gone. The book itself also contains information: the microprice from the order-book lesson is the static version of this same calculation.
Worked example
what is a queue position worth?
A bid queue holds 12 lots including yours, the ask queue holds 10, and the tick is worth 1 unit. Use the fill model above (, , ) and the mark-out formula. For simplicity assume no one joins behind you while you wait, so if you have lots ahead you will have behind you when filled. Value your order (expected mark-out per order placed, zero if unfilled) at positions , 5 and 10. Should a market maker at who could cancel and re-join elsewhere care?
Show solutionHide solution
Value .
| Position | Behind at fill | Mark-out | Value | |
|---|---|---|---|---|
| 0.830 | 10 | |||
| 0.598 | 6 | |||
| 0.423 | 1 |
(For : , so the mark-out is .)
The front of the queue is worth about 0.42 ticks per order; near the back the same order loses about 0.16 ticks in expectation. Both effects point the same way: the back of the queue fills less often and its fills are worse. This is why queue position is a scarce asset in large-tick markets, why firms invest in latency to join new price levels first, and why a market maker near the back of a thin queue often cancels rather than waits. (The no-joiners assumption overstates the effect, since new orders behind you protect you; the ranking survives.)
Out loud: "My order's value is fill probability times expected mark-out. Fill probability falls roughly geometrically with queue ahead; mark-out falls with how little is left behind me, because a fill at the back means the level is about to clear."
Where queues matter, and where they do not
- Price-time priority (FIFO) markets reward being early at a price level. Queue position is the asset; tick size determines how valuable it is. A large tick relative to price creates long queues and a big gap between the front and the back.
- Pro-rata markets (some interest-rate futures) allocate fills in proportion to size, so position matters less and participants post inflated sizes instead.
- Small-tick stocks often have short queues and frequent price changes, so the battle is about price improvement (quoting a new level) rather than position.
- Measuring it in practice: you rarely see the full queue order by order, so desks estimate queue position from their own order's timestamp plus the visible size changes at the level, assuming cancellations come from behind them unless proven otherwise (a conservative choice).
How this comes up in interviews
- "You have a bid at the best price with 500 shares ahead. What is the chance you get filled?" Set up the race between depletion (market orders plus cancellations ahead) and the price moving away, write the product formula, and say it decays roughly geometrically.
- "Why might a limit order lose money on average even though it earns the spread?" Adverse selection conditional on fill: fills are concentrated when the level is about to clear.
- "Would you rather be first in a queue of 1,000 or last in a queue of 10?" First of 1,000: nearly certain fill and a thick queue behind you protecting your mark-out. Last of 10 fills only if the level is being cleared.
Knowledge check
Nobody cancels (). Market sells arrive at rate 2 per second and the price moves away at rate 0.5 per second. You have 3 lots ahead of you. What is your fill probability?
Knowledge check
Two of your bids are filled at the same price on different days. On day A the fill left 40 lots behind you at the bid; on day B it left 2. The ask queue was 15 lots both times. Which fill has the better expected mark-out?
Knowledge check
In the fill model, cancellations by orders ahead of you become more frequent (theta rises) while everything else is unchanged. What happens?
Key takeaways
- Fill probability is a race between queue depletion (market orders plus cancellations ahead) and the price moving away: , roughly geometric in queue position.
- Fills are selected: conditional on being filled near the back, the level is likely to clear next. Mark-out ticks in a one-tick market, with .
- Order value fill probability expected mark-out; both fall with queue position, so the front can be worth a large fraction of a tick and the back can be negative.
- Queue position matters most in large-tick FIFO markets; pro-rata and small-tick markets change the game.
Practice problems
Finished reading?
Answer the 3 knowledge checks to complete this lesson (0 done).