Execution: how an order becomes a fill, and what it costs on the way
On this page
The frictions and capacity post ended on a question it left open: a fund that needs a whole day’s volume cannot send it as one market orderAn order where the broker simply accepts whatever price the market is offering., so how does a large order actually get filled? This post is the answer the execution chapters of the CFA Institute’s Handbook of Artificial Intelligence and Big Data Applications in Investments give, worked with numbers. Execution happens inside the trading day, and the blog’s price file holds one closing price a day with no volume and no quotes. So the order, the day and the order book here are made up, and every made-up number is labelled as one. The real prices (SPY, NVDA, GS, XOM, GLD, January 2020 to October 2025) answer one question the made-up day cannot: how far a price wanders while an order waits.
The made-up case, used all the way through:
- A fund decides to buy 20,000 shares of a stock. At that moment the best bid is $49.98 and the best ask $50.02, so the mid, halfway between, is $50.00.
- The stock trades 1 million shares a day, in six trading intervals from the open to the close, with more volume near the open and the close than at midday.
- The fund has the whole day to finish.
The benchmark: what a fill is measured against
The chapter by Nagy, Powrie and Zohren (chapter 8) states the problem in one sentence: “The execution algorithm is presented with a block of shares to buy or sell within a required time frame, which typically ranges from seconds to hours.” The cost it measures is slippageThe gap between the price that triggers an order and the price it actually fills at; on average a cost., “the difference between a reference price before the start of the trade and the prices at which trades are executed”. The usual reference is the arrival priceThe mid price when an order reaches the trading desk, the price the decision to trade was made on., the mid when the order arrives at the trading desk, because that is the price the decision was made on.
slippage, the costaverage fill, the price the fund paidreference price, what it is measured against
Here is the share-weighted average price of all the fills, the reference price, and side is for a buy and for a sell, so a positive slippage is always a cost: a buyer who pays more than the reference, or a seller who gets less.
The arrival price is not the only reference in use. Trading desks also measure a fill against the VWAPThe average price weighted by volume; as a schedule, slices sized in proportion to the volume expected in each interval., the volume-weighted average price, which is the average price the whole market paid over the same window:
VWAP, what the market paid on average
where is the price in interval and the shares traded in it. The TWAPSplitting an order into equal slices spaced evenly over the time allowed; the baseline execution schedule., the time-weighted average price, is the plain average of the prices, every interval counting the same.
On the made-up day the mid drifts up from $50.00 at the open to $50.12 at the close. The fund buys in six slices that follow the day’s volume (the VWAP schedule, Table 3), and every slice crosses the spread, so each fills at its interval’s mid plus 2 cents. Its average fill comes out at , and the market’s VWAP for the day is . Against the two references, the same fills tell two stories (Table 1):
| Reference | Reference price | Slippage (cents a share) | Slippage on the order |
|---|---|---|---|
| Arrival price | $50.000 | 7.90 | $1,580, or 15.8 basis points |
| Market VWAP | $50.059 | 2.00 | $400 |
Against VWAP the fund paid only the half-spread, 2 cents a share. Against the arrival price it paid 7.9 cents, because the market’s average price over the day was 5.9 cents above the arrival price: the price rose while the order was still being filled. Both numbers are true. They answer different questions: the VWAP number asks whether the fund traded as well as everyone else that day, the arrival number asks what the decision to buy cost once it met the market.
A schedule that follows the market’s volume tracks VWAP when the volume forecast is right, so beating or matching VWAP says little about what the trade cost. The 5.9 cents the price moved during the day sit inside the VWAP and never show up against it.
The CFA chapter by Stanton (chapter 7) labels each order’s observed cost implementation shortfallWhat an order actually cost against the price when the decision to trade was made., and uses it as the observed cost that a cost model learns to predict, and its Exhibit 4, “Precleansed Data Noise in a Typical Dataset”, shows why that is hard: two AAPL training examples five minutes apart on the same day, 1,000 and 1,100 shares, with spreads of 10 and 9 basis pointsOne hundredth of a percent, 0.01%., and observed costs of 5 and 20 basis points. Near-identical orders, four times the cost. The chapter’s explanation is that “there may be other factors not captured in traditional TCA analysis that can affect a trade”, TCA being transaction costWhat each trade costs: the broker's commission plus the bid-ask spread paid when buying and selling at market prices. analysis. One order’s cost says little about the method that executed it; the method shows only in the average over many orders.
Slicing: impact against waiting
Why not buy all 20,000 shares at once? Chapter 8 answers: executed as one market order, “large buy orders would push prices up, sell orders would push them down, or there might simply not be enough liquidityLiquid markets have large trading volumes, many market makers and the smallest spreads; widening spreads are an early sign liquidity is freezing up. in the market at the time to complete the trade”. The fix is to split the order “into smaller slices that are then executed over the available time horizon”.
Put a made-up book under the made-up stock: 2,000 shares offered at every cent from the ask upwards, $50.02, $50.03, $50.04 and so on, and assume the book refills between slices (a generous assumption; the what a trade costs post walks a book the same way). One market order for 20,000 shares empties ten levels, from 2 to 11 cents above the mid, and pays cents a share on average. Six slices of about 3,333 shares each empty one level and part of the next, and pay cents. Slicing saves 4.1 cents a share, $820 on the order.
What slicing buys in impact it pays for in time. Chapter 8: “In any execution problem, there is a trade-off between the price impact and the risk of the price moving unfavorably over the execution horizon.” The shares not yet bought are exposed to whatever the price does next. How much is that? This is where the real prices come in. For a price whose daily moves are independent, the typical move over days grows with the square root of the time:
σ, the typical one-day move, and the typical move over d days
where is the standard deviationThe square root of the variance, a measure of spread in the same units as the data. of daily returnsThe percentage change in price from one day to the next: today's price divided by yesterday's, minus one. and the standard deviation of returns over days. Table 2 measures both on the five tickers, so the rule does not have to be taken on trust.
| Ticker | One day (%) | Five days, measured (%) | Five days, square-root rule (%) |
|---|---|---|---|
| SPY | 1.32 | 2.67 | 2.95 |
| NVDA | 3.37 | 7.04 | 7.55 |
| GS | 2.08 | 4.52 | 4.65 |
| XOM | 2.09 | 4.53 | 4.67 |
| GLD | 1.03 | 2.27 | 2.29 |
The rule is close for all five and a little high for each, most for SPY (10%) and NVDA (7%), whose five-day moves were smaller than five independent days would give. Figure 1’s second panel draws the measured spread for SPY and NVDA out to ten days against the rule.
The price file is daily, so the check stops at one day. For a horizon inside the day the post assumes the same rule, which it cannot test here. With that assumption, a $50 stock that moves like SPY has a typical move of cents over a day, and cents over one of the six intervals. Compare that with the 4.1 cents slicing saved. The waiting does not cost 27 cents on average: for a trader with no view on the direction, the expected move is zero, and only its spread grows. That is the reason chapter 8 gives for its baseline: “If we are risk neutral and have no information on the direction the price is likely to move or on future trading activity, the optimal execution schedule involves partitioning all trades into smaller slices spaced evenly over the execution horizon.” A trader who does care about the spread of outcomes may trade faster and pay more impact; the chapter’s example is that “In periods of high volatilityHow much an asset's price spikes and dips; most often measured as the standard deviation of its per-period returns., for example, it might pay to front-load the execution schedule to limit exposure to the downside risk of adverse price shocks.”
Slicing turns a cost you can estimate (impact) into a risk you do not (where the price goes while you wait). How fast to trade is a choice between the two, and the answer changes with the volatility of the stock.
TWAP and VWAP: two ways to cut the order
The evenly spaced schedule in that quote is TWAP execution, and chapter 8 calls it “a benchmark for more advanced execution algorithms to surpass”. The second standard schedule uses volume. A higher volume “allows larger trades to be executed for the same amount of price impact”, so VWAP execution splits the order “over time proportionately to the expected volume profile”. With shares to buy over intervals and the volume expected in interval :
the slice, shares to buy in interval k
Table 3 puts both on the made-up day.
| Interval | Expected volume (shares) | Share of the day | TWAP slice (shares) | VWAP slice (shares) |
|---|---|---|---|---|
| 1, the open | 250,000 | 25% | 3,333 | 5,000 |
| 2 | 150,000 | 15% | 3,333 | 3,000 |
| 3 | 100,000 | 10% | 3,333 | 2,000 |
| 4 | 100,000 | 10% | 3,333 | 2,000 |
| 5 | 150,000 | 15% | 3,333 | 3,000 |
| 6, the close | 250,000 | 25% | 3,333 | 5,000 |
On this day the VWAP schedule is 2% of the market’s volume; the TWAP schedule is 1.3% of the volume at the open and 3.3% at midday, when the market trades least (Figure 1, first panel). Chapter 8 cites results that VWAP execution is optimal “under the assumptions of risk neutrality and permanent market impactThe move in market prices caused by your own order; a large part of the trading cost when the security is not very liquid.” when volume is known. It is not known; it is forecast, and the chapter notes that volume “shows patterns depending on the time of day and can be predicted reasonably accurately”, from a simple time-of-day profile up to deep learningThe branch of machine learning built on neural networks. models. TWAP needs no forecast at all.
Passive or aggressive: price against certainty
Each slice still has to be sent as an order, and there are two kinds. An aggressive order crosses the spread: a buy at the ask, filled now. A passive order is a limit orderAn order that sets a price condition before it can be executed, such as buy only at 200 dollars a share or less. that waits in the book at the near side: a buy at the bid, filled only if a seller comes to it. Chapter 8 puts numbers on the difference: crossing the spread means “half the spread is lost with every trade relative to the mid-priceThe price halfway between the best bid and the best ask.”, even if the mid never moves, while placing at the near touch “has the opposite effect of earning half a spread”. The catch is in the next sentence: “The downside of passive orders is that execution is uncertain and depends on other market participants’ order flow and future price moves.”
On the made-up stock, a passive buy at $49.98 that fills saves the whole 4-cent spread against buying at the ask now. One that does not fill leaves the fund to buy later; suppose, as a made-up number, that by then the ask has moved up 6 cents. The value of waiting, per share, against buying now:
fill probability, the chance the passive order fillswhat a miss costs
With 4 cents saved and a 6-cent miss, the break-evenThe cost per trade at which a strategy's whole gain over the period is used up by trading costs. fill probabilityHow often an event happens if you could repeat a trial without end: the share of trials where it happens. is , 6 cents over 10. At a fill probability of waiting gains 2 cents a share on average; at it loses 2. A passive order is not free just because its price is better. Its price is better only for the shares that fill.
What sets the fill probability? Partly the queue. The book matches “using a price–time priorityThe matching rule of an order book: best price first, and orders at the same price in order of arrival. matching mechanism”: the best price first, and at the same price “on a first-come, first-served basis”. Suppose the fund joins the bid at $49.98 with 5,000 shares, behind 12,000 shares already waiting there, and a market sell order for 15,000 arrives. It fills the 12,000 ahead first and then 3,000 of the fund’s 5,000. A seller of 12,000 or fewer would have filled none of the fund’s shares. Cancelling and re-entering the order at a new price moves it to the back of the queue at that price.
Chapter 8 also names a middle way that practitioners use: limit orders “targeted against the best bid or ask”, often as immediate-or-cancelA limit order that is cancelled automatically if it cannot be filled at its limit price straight away. orders, “which are automatically canceled if they cannot be filled at the limit price”. They take what is there at a known worst price and never sit in the book.
What the order book says about the next few seconds
The book also predicts, a little. Chapter 8 gives the order book imbalanceShares at the best bid minus shares at the best ask, over their sum; from -1 to +1, a hint of the next price move., the normalised difference between the shares waiting at the best bid and at the best ask:
imbalance and micro-price
where and are the shares at the best bid and best ask, and and their prices. The imbalance runs from , “a strong downward price pressure”, to , “a strong upward price pressure”. The micro-priceThe bid and ask prices weighted by the order book imbalance; closer to the true fair price than the mid. weighs the two prices by the imbalance, which the chapter says “more closely reflects the microstructure effects than the mid-price”.
On the made-up book, with 8,000 shares bid at $49.98 and 2,000 offered at $50.02, the imbalance is , , and the micro-price is , above the $50.00 mid: the chapter’s “upward price pressure”, a price more likely to tick up than down. A buyer who reads that has a reason to cross now rather than wait at the bid. The chapter is clear on the horizon, though: these are signals for “short-term price changes”, seconds, and it reports that in one study plain linear models and simple feed-forward networks “are not useful for forecasting such short-term alpha signals”. A snapshot of the book is also only a snapshot; the chapter notes that “a continuous order flow changes the book dynamically over time”.
Chapter 8 then shows where these pieces meet: volatility forecasts set how much to front-load, volume forecasts size the slices, and short-term price forecasts choose the price level for each slice. It adds one more reason to vary the placement at random: “A probabilistic strategy also has the benefit of being less predictable by other market participants, who might want to exploit the effect that large orders have in moving the market.”
Check yourself
A fund matched the day's VWAP. Why can its purchase still have been expensive?
Because VWAP already contains everything the price did that day. On the made-up day the fund paid 2 cents a share against VWAP but 7.9 cents against the arrival price: the 5.9 cents the price rose while the order was being filled sit inside the VWAP and never show up against it.
Slicing saved 4.1 cents a share of impact. What does the fund pay for that instead?
Time. The shares not yet bought are exposed to whatever the price does next. For a $50 stock that moves like SPY, the typical move over one of the six intervals is about 27 cents; for a trader with no view on the direction its expected valueThe probability-weighted average of a quantity over all the values it can take. is zero, but the spread of outcomes grows.
A passive order saves 4 cents if it fills; a miss costs 6. What fill probability makes it worth waiting?
Above 60%, the break-even: 6 / (4 + 6). At 80% waiting gains 2 cents a share on average; at 40% it loses 2. The better price only counts for the shares that fill.
Traps
Table 4 has the beliefs this post set out to correct.
| People think | Actually |
|---|---|
| The price on the screen is the price you pay | a buy crosses to the ask; on the made-up stock that is 2 cents above the mid before any impact |
| Beating VWAP means the trade was cheap | the same fills cost 2.0 cents against VWAP and 7.9 against the arrival price |
| One order’s slippage shows how good the execution was | two near-identical AAPL orders cost 5 and 20 basis points |
| Slicing makes the cost go away | it lowers impact (6.5 to 2.4 cents) and leaves the rest of the order exposed while it waits |
| A passive order saves the spread | only on the shares that fill; with a 6-cent miss it needs a fill probability above 60% |
| TWAP is a naive schedule | it is the optimal one for a risk-neutral trader with no forecast of price or volume |
The code
The snippet reproduces Table 3’s slices, Table 1’s two slippages, the slicing saving, the break-even fill probability, the micro-price and Table 2. Table 5 names its variables.
| Variable | Holds |
|---|---|
vol | the made-up day’s expected volume in each of six intervals |
mid | the made-up mid price in each interval |
twap, vwap | shares bought in each interval by the two schedules |
px | the real adjusted closes, one column per ticker |
import numpy as np
import pandas as pd
Q, arrival = 20_000, 50.00 # made-up order: buy 20,000 shares
vol = np.array([25, 15, 10, 10, 15, 25]) / 100 * 1_000_000
mid = np.array([50.00, 50.04, 50.06, 50.05, 50.08, 50.12])
twap = np.full(6, Q / 6) # equal slices
vwap = Q * vol / vol.sum() # slices follow the volume
print("VWAP slices:", vwap.astype(int))
fill = mid + 0.02 # every slice crosses the spread
avg = (fill * vwap).sum() / Q
market_vwap = (mid * vol).sum() / vol.sum()
print(f"vs arrival {100 * (avg - arrival):.2f}c, vs VWAP {100 * (avg - market_vwap):.2f}c")
def walk(shares, depth=2_000, first=2): # cents above the mid, book refills between slices
full, rest = divmod(shares, depth)
return (sum(depth * (first + k) for k in range(int(full))) + rest * (first + full)) / shares
print(f"one order {walk(Q):.2f}c, six slices {walk(Q / 6):.2f}c")
saved, miss = 4, 6 # cents, against buying at the ask now
print(f"break-even fill probability {miss / (saved + miss):.0%}")
db, ds, pb, ps = 8_000, 2_000, 49.98, 50.02
I = db / (db + ds)
print(f"OBI {(db - ds) / (db + ds):.2f}, micro-price {I * ps + (1 - I) * pb:.3f}")
url = "https://raw.githubusercontent.com/ankurtrapasiya/examples/main/data/prices.csv"
px = pd.read_csv(url, index_col="date", parse_dates=True)
for t in px.columns:
one = 100 * px[t].pct_change().std()
five = 100 * px[t].pct_change(5).std() # overlapping five-day returns
print(f"{t}: one day {one:.2f}%, five days {five:.2f}%, rule {one * np.sqrt(5):.2f}%")
It prints the VWAP slices 5,000, 3,000, 2,000, 2,000, 3,000 and 5,000; 7.90 cents against arrival
and 2.00 against VWAP; 6.50 cents for one order and 2.40 for six slices; a break-even of 60%; an
imbalance of 0.60 and a micro-price of 50.012; and the rows of Table 2, SPY 1.32%, 2.67% and
2.95%. divmod(shares, depth) returns how many price levels the order empties completely and how
many shares are left for the next one.
The script behind the real numbers
The tables and the chart come from
examples/execution-how-an-order-becomes-a-fill/execution.py,
which runs on the blog’s five tickers. To run it yourself, clone the examples repo: its README has a three-command Docker setup, or run uv run execution-how-an-order-becomes-a-fill/execution.py.
Summary
Table 6 collects the ideas, with the number behind each.
| Idea | In one line | The number behind it |
|---|---|---|
| Slippage | average fill against a reference price, signed so positive is a cost | 7.9 cents a share against the arrival price |
| Benchmark choice | VWAP measures trading against the market, arrival measures the decision | 2.0 cents against VWAP for the same fills |
| Slicing | trades impact for exposure to the price while the order waits | 6.5 cents as one order, 2.4 as six slices |
| TWAP and VWAP | equal slices, or slices that follow the expected volume | 3,333 a slice, or 5,000 at the open and 2,000 at midday |
| Passive orders | earn the half-spread only on the shares that fill | break-even fill probability 60% |
| Book imbalance | more shares on one side hints at the next tick | imbalance 0.60, micro-price 50.012 against a 50.00 mid |
References
- Peer Nagy, James Powrie and Stefan Zohren, “Machine Learning for Microstructure Data-Driven Execution Algorithms”, chapter 8 of the CFA Institute Research Foundation’s Handbook of Artificial Intelligence and Big Data Applications in Investments (2023). The execution problem and slippage, slicing and the impact-against-risk trade-off, TWAP as the optimal schedule without information, VWAP and volume forecasts, front-loading in high volatility, price–time priority, immediate-or-cancel orders, half the spread lost or earned, order book imbalance and the micro-price, the limits of linear models for short-term signals, and probabilistic placement.
- Erin Stanton, “Machine Learning and Big Data Trade Execution Support”, chapter 7 of the same Handbook. Implementation shortfall as the observed cost outcome, and Exhibit 4’s two AAPL orders with near-identical inputs and different costs.