Free lesson · HFT & microstructure
Order-book features: imbalance, microprice and event flow
Open interactive lessonPractice calculationsExplore labs
Start with the idea
The order book is a state of displayed intentions. Prices describe where liquidity is offered; quantities describe how much is displayed. Their imbalance can inform a conditional forecast, but displayed liquidity can disappear before you reach it.
Symbols, units & horizon
- b,a: best bid and ask prices with a≥b
- Q_b,Q_a: displayed sizes at those prices in matching units
- I: depth imbalance between −1 and 1
- m: midpoint
- m_μ: simple size-weighted microprice
- a−b: quoted spread
- Positive total displayed depth: required denominator
When and why to use this
Use book features to forecast future marks or fill outcomes, keeping the prediction target distinct from executable prices.
Start with best bid, best ask, spread, displayed depth and changes in depth. Distinguish snapshots from events: a queue can shrink because of trades or cancellations, which have different informational content. Level-2 data may not identify individual queue positions; level-3 data can improve reconstruction where available.
A simple microprice weights the ask more heavily when bid depth dominates, giving a price-like summary of imbalance. It is a feature, not a fair execution price. Price distance, multiple depth levels, signed trades, arrival intensity and recent cancellations can extend the state.
Normalise quantities by time-of-day and venue conventions using training data. Use only complete messages and causal rolling windows. Auction periods, locked/crossed books and stale quotes deserve explicit handling rather than silently filling missing values with future observations.
Order-book features: imbalance, microprice and event flow
- Express bid and ask as midpoint minus and plus half the spread.
- Substitute a=m+(a−b)/2 and b=m−(a−b)/2 into the weighted average.
- The common midpoint term reduces to m; the remaining term is half-spread times (Q_b−Q_a)/(Q_b+Q_a).
Bid 100, ask 100.02, bid depth 300 and ask depth 100 give I=.5, midpoint 100.01 and microprice 100.015. This does not mean a buy can execute at 100.015.
Apply it in a strategy
- Reconstruct valid books from sequence-checked messages and retain the information-availability timestamp.
- Compare a linear imbalance model with richer event features on held-out sessions.
- Evaluate conditional markouts and net fills, not just next-tick classification accuracy.
Research deliverable
Build a feature dictionary with event source, window, units, release time and invalid-book policy for every field.
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 book_features(bid,ask,bid_size,ask_size):
if ask<bid or min(bid_size,ask_size)<0 or bid_size+ask_size<=0: raise ValueError("Invalid book")
imbalance=(bid_size-ask_size)/(bid_size+ask_size)
midpoint=(bid+ask)/2
return imbalance,midpoint,(ask*bid_size+bid*ask_size)/(bid_size+ask_size)
print(book_features(100,100.02,300,100))Continue learning
High-Frequency Trading: Signals, Queues & Execution — all lessons- HFT economics and the information-to-fill timeline
- Order-book features: imbalance, microprice and event flow
- Volume clocks, trade imbalance and VPIN
- Queue position, fill probabilities and adverse selection
- Inventory-aware quoting and economic edge development
- Event-driven backtesting and order lifecycle correctness
- HFT research promotion, drift and operating limits
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations