Market Microstructure Calculator — Microprice & Order Imbalance
Compute market microstructure signals: top-of-book microprice, order imbalance, Kyle price impact, Roll effective spread, and realized and bipower variation.
High-Frequency Market Microstructure Analysis
A clear path from inputs to results.
See the standard market-microstructure signals computed from a limit order book and a trade tape. The core turns best bid and ask quotes, their sizes, and order flow into the top-of-book microprice, the order imbalance, Kyle price impact, the Roll effective spread, and realized and bipower volatility. It is a reference implementation of the equations desks use to read short-horizon price pressure, so you can tie each number back to its source formula rather than a black box.
How to use
- Set the best bid and best ask prices and the resting sizes on each side; these define the quoted spread and the order imbalance.
- Set the base mid, base spread, and the trade size q used to drive the deterministic tape of microstructure events.
- Set the Kyle lambda, the linear price-impact coefficient that maps signed order flow into price moves.
- Set the noise level and the tape length to control how much microstructure noise is injected and how many events are simulated.
- Read the top-of-book microprice and order imbalance, the mean Kyle impact, and the Roll effective-spread estimate from the serial covariance of price changes.
- Read the realized variance and bipower variation, and compare them on the signature plot across sampling frequencies to see the noise-versus-bias tradeoff of high-frequency estimators.
The formula
Reference: Kyle (1985), "Continuous Auctions and Insider Trading", Econometrica 53(6); Glosten & Milgrom (1985); Roll (1984), "A Simple Implicit Measure of the Effective Bid-Ask Spread"; Barndorff-Nielsen & Shephard (2004) for realized and bipower variation; Ait-Sahalia, Mykland & Zhang (2005) for the signature plot.
Worked example
Top-of-book microprice from a quoted order book
- Best bid 99.98 with 820 lots resting, best ask 100.02 with 760 lots resting.
- 1
The mid is M = (99.98 + 100.02)/2 = 100.00 and the quoted spread is S = 100.02 - 99.98 = 0.04. The order imbalance is I = (V_b - V_a)/(V_b + V_a) = (820 - 760)/(820 + 760) = 60/1580 = 0.037975, positive because the bid side is heavier. The size-weighted top-of-book microprice is P_mu = (P_a*V_b + P_b*V_a)/(V_b + V_a) = (100.02*820 + 99.98*760)/1580 = 158001.2/1580 = 100.000759. This equals the identity form M + (S/2)*I = 100 + 0.02*0.037975 = 100.000759 exactly, confirming the microprice sits above the mid by half the spread scaled by the imbalance.
Mid 100.000000, spread 0.040000, order imbalance 0.037975, top-of-book microprice 100.000759 (0.76 ticks of a 0.04 spread above the mid, pulled toward the ask by the heavier bid side).
Interpreting the result
The microprice is the fair value implied by the book: when the bid size exceeds the ask size the imbalance is positive and the microprice sits above the mid, anticipating an upward move, which is why it predicts short-horizon price changes better than the mid. Kyle lambda measures how much a unit of signed order flow moves the price, so a larger lambda means a less liquid, more impactful market. The Roll estimator backs out the effective spread from the negative serial correlation that bid-ask bounce induces in trade prices, and realized versus bipower variation separates total variation from its continuous part, with their gap flagging jumps.
Assumptions & limitations
- The order book is reduced to the top of book (best bid and ask with their sizes); depth beyond the touch is not used in the microprice.
- The tape of microstructure events is deterministic and synthetic, built from explicit sinusoidal imbalance and impact patterns rather than a stochastic order-flow model, so the per-event series is reproducible but illustrative.
- Price impact is linear in signed order flow (Kyle), with a single constant lambda; nonlinear or transient impact is not modeled.
- The Roll estimator returns a positive spread only when the serial covariance of price changes is negative; when that covariance is non-negative it reports zero, as the model intends.
- Realized and bipower variation are computed on the simulated return series and are sensitive to the sampling frequency, which the signature plot is designed to expose.
- Bipower variation uses the constant mu_1 = E|N(0,1)| = sqrt(2/pi) in its scaling, the standard Barndorff-Nielsen and Shephard normalization.
Frequently asked questions
What is the microprice and why not just use the mid?
The microprice is the size-weighted average of the best bid and ask, P_mu = (P_a*V_b + P_b*V_a)/(V_b + V_a), which equals the mid plus half the spread times the order imbalance. Because it leans toward the side with less size (the side likely to be hit), it is a better short-horizon predictor of where the price goes next than the simple mid. When the two sizes are equal the imbalance is zero and the microprice collapses back to the mid.
How does the Roll estimator recover the spread?
Roll (1984) observed that bid-ask bounce makes consecutive trade-price changes negatively correlated: a buy at the ask followed by a sell at the bid creates a reversal. The effective spread is 2 times the square root of minus that serial covariance, S = 2*sqrt(-Cov(Delta p_t, Delta p_{t-1})). It only yields a positive number when the covariance is negative; a non-negative covariance (as can happen with a trending synthetic tape) returns zero.
What is the signature plot telling me?
The signature plot shows realized variance as a function of sampling frequency. Sampling too finely picks up microstructure noise and inflates the estimate; sampling too coarsely throws away data and adds variance to the estimate. The plot visualizes this bias-variance tradeoff from Ait-Sahalia, Mykland and Zhang (2005), which is why practitioners sample at an intermediate frequency or use noise-robust estimators.
What does Kyle lambda measure?
Lambda is the slope of the linear price-impact relation Delta p = lambda*q + noise, so it says how many price units a unit of signed order flow moves the market. A higher lambda means a thinner, more impactful market where trading moves prices more; a lower lambda means deeper liquidity. It is the inverse of market depth in Kyle's (1985) model of informed trading.
What is the difference between realized variance and bipower variation?
Realized variance sums squared high-frequency returns and captures total variation, including jumps. Bipower variation sums products of adjacent absolute returns, scaled by mu_1^{-2}, and is robust to jumps so it estimates only the continuous (diffusive) part. The gap between them is a jump detector: when realized variance sits well above bipower variation, the path contains jumps.
Is this using real market data?
No. The tape is a deterministic synthetic sequence built from explicit microstructure equations, so every curve is exactly reproducible and each statistic can be traced to its formula. The point is to show how the microprice, imbalance, Kyle impact, Roll spread, and volatility estimators are defined and interact, not to analyze a specific instrument's live book.
Methodology last reviewed 2026-10-06. Results are informational and not financial or engineering advice — see our disclaimer.