Free lesson · Execution & microstructure
The spread is a price for immediacy
Open interactive lessonPractice calculationsExplore labs
Start with the idea
The bid and ask are executable offers at limited quantities; the mid is a reference. A narrow spread can coexist with little depth, while a large displayed queue can disappear before an order arrives.
Symbols, units & horizon
- aₜ,bₜ: best ask and bid in price units
- mₜ: midpoint
- sₜ: full spread in price units
- s_bp: full spread in basis points of midpoint
- V_b,V_a: displayed bid and ask quantity at the defined depth
- Iₜ: dimensionless displayed imbalance from −1 to 1
- 10⁴: convert fractional price to bp
When and why to use this
Use spread and depth to estimate whether a forecast is economically tradable and to choose order size or urgency. Use imbalance as a testable feature rather than a narrative about buyer dominance.
Convert quote geometry into basis points
- The midpoint is the arithmetic average . Spread is ask minus bid. Divide spread by mid for a relative price difference and multiply by 10,000 for bp.
- For an ideal fill at the touch, one-way spread cost relative to mid is approximately half the quoted spread.
Bid 99.99, ask 100.01 gives mid 100, spread .02 and quoted spread 2 bp. One-way touch cost is about 1 bp.
The best ask a is the lowest visible sale offer and the best bid b is the highest visible purchase offer. The midquote m is a reference, not necessarily an executable price. A marketable order crosses the spread and can walk through multiple price levels.
A resting limit order controls price but not execution. A quote touching your limit does not establish that your order was filled: queue priority, available volume, cancellations, and feed latency matter. Passive fills can be adversely selected when informed flow arrives just before the market moves against you.
Normalise displayed book imbalance
- Take signed difference B−A and divide by total B+A. Since |B−A|≤B+A for nonnegative sizes, imbalance lies in [−1,1] when total is positive.
- With total depth V, solve and .
Bid size 300 and ask size 100 give I=.5. A 400-unit total and I=.5 imply 300 bid and 100 ask.
Top-of-book imbalance uses displayed bid and ask size. It ranges from −1 to 1 when total size is positive; it is undefined when both are zero. It can be short lived, venue specific, and distorted by cancellations. Validate it against future executable returns rather than midquote changes alone.
Research sources, review dates and limitations
Capstone checkpoint 6 / Reconcile the result
Synthetic exercise · self-assessed. Follow the capstone’s 25-share purchase at $100 and sale at $100.92, with a $0.25 fee on each fill. Reconcile ending cash, then explain why adding a $500 deposit does not change investment profit.
Save in your practice notes: An event ledger with cash, holdings, fees and external flows. Open practice studio →
The flat account ends at $10,022.50 before the deposit. Slippage already in the fill price must not be subtracted again.Check your reasoning
Python implementation
Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.
def quote_metrics(bid, ask, bid_size, ask_size):
if not 0 < bid <= ask or min(bid_size,ask_size) < 0 or bid_size+ask_size == 0:
raise ValueError("Valid positive quotes and nonzero displayed depth required")
mid = (bid+ask)/2
spread = ask-bid
imbalance = (bid_size-ask_size)/(bid_size+ask_size)
return mid, spread, 10000*spread/mid, imbalance
print(quote_metrics(99.99,100.01,300,100))Continue learning
Execution & Market Microstructure — all lessons- The spread is a price for immediacy
- Measure implementation shortfall
- Capacity is where alpha meets market impact
- Make the order lifecycle auditable
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations