Back to articles

How to Read the Order Book Like a Quant. Every Model, Every Formula, Runnable Code

verax · @journoverax · Mar 19

View original post
How to Read the Order Book Like a Quant. Every Model, Every Formula, Runnable Code cover

You'll learn how to build a high-octane simulation engine for trading prediction markets - stepping up from basic Monte Carlo methods to a full-scale market maker with inventory management, order flow modeling, and bulletproof protection against informed traders.

*Disclaimer: Not Financial Advice & Do Your Own Research*

**Part I: The Spread That's Bleeding You Dry

**You're looking at a Polymarket order book. The contract: "Will Trump win Pennsylvania?" Bid - $0.61, Ask - $0.65.

Spread of $0.04. Seems like nothing.

You buy at $0.65. The contract resolves YES. You collect $1.00. Profit of $0.35, right?

No.

You just paid $0.04 to the market maker on entry. If you want to exit before resolution - you'll pay another $0.04. Total: $0.08 on a $1.00 contract. That's 8% in implicit transaction costs. On the NYSE, the spread for liquid stocks is 0.01-0.02%. You're trading an instrument where the rake against you is 400 times the equity average, and you don't even know why.

Now it gets worse. The spread is not a constant. It shifts depending on:

  • Time to resolution
  • Trading volume
  • Information asymmetry between participants
  • The probability that the other side knows something you don't

That last point is Kyle's model. And it's where any real understanding of the order book begins.

Part II: Kyle's Lambda - The Price of Information

In 1985, Albert Kyle wrote a paper that explained why price impact exists at all.

Imagine three participants:

  • The insider - knows the true asset value *v*
  • The market maker - doesn't know *v *, but sees the aggregate order flow
  • Noise traders - trade randomly (not from information)

The market maker sets a price by watching the total flow *y = x + u*, where *x* is the insider's order and *u* is random noise.

In Kyle's equilibrium, the price is a linear function of flow:

where *is Kyle's lambda - the price impact coefficient:

σ*v​ * is uncertainty about the true value; σ*u* is the standard deviation of noise orders**

What this means in practice:** if you see a 5,000 order move a contract from $0.62 to $0.67, then $\lambda \approx 0.001per dollar of volume. High lambda = the market thinks large players have information. Low lambda = a liquid market where big orders are just noise.

Estimating Lambda From Data

If *R²* exceeds 0.15 - informed traders are active. Widen your spread or stay out entirely.

Part III: Order Flow as a Point Process

Now: when do orders actually arrive?

The naive answer is uniformly over time. That's wrong. Real order flow clusters: a news event hits -> a burst of trades -> quiet -> another burst.

This pattern is described by the Hawkes process - a self-exciting point process where each event raises the probability of the next one.

Order flow intensity:

Where:

  • * - baseline intensity (background flow)
  • * - how much each trade excites future ones
  • * - decay rate of that excitement
  • Stationarity condition: *α < β* (otherwise: activity explosion)

The ratio α/β is the branching ratio: the fraction of orders generated by previous orders rather than exogenous news. On liquid markets it runs 0.5-0.9. Most trades are reactions to other trades - not to new information.

Fitting a Hawkes Process to Historical Orders

Why does this matter on Polymarket? If the branching ratio suddenly jumps from 0.6 to 0.85 - something happened and the market is running hot. A market maker should be widening the spread, not tightening it.

Part IV: Optimal Execution - Stop Donating Money

Say you want to buy a $10,000 position in a contract priced at $0.55.

You could buy it all at once. But your order will move the price - you'll be trading against yourself. Price impact scales with size:

The optimal execution problem: split QQ into pieces {q1,q2,...,q*n*} to minimize total transaction costs while accounting for market risk.

The Almgren-Chriss model (2001) solves this in closed form.

Let X*k* be the remaining position at step *k, τ = T/N* the length of each interval.

The optimal execution trajectory:

where: * is the urgency parameter, *σ~2* is the risk-adjusted variance, and *is the permanent component of market impact.

Higher risk_aversion means trade faster - larger early orders. Lower means spread it evenly. This is not abstract: on Polymarket, sloppy execution of a $10k position can cost $200-$400 in avoidable slippage.

Part V: A Market Maker With Dynamic Hedging

Now we assemble everything into a working bot.

The Avellaneda-Stoikov market-making strategy (2008): the market maker quotes bid and ask around a "fair price" r*t* - not the market mid, but an inventory-adjusted reservation price:

where *q* is current inventory (positive = long YES tokens), S*t* is the mid-price.

Then:

Here * is the intensity of incoming executions, * is the market maker's risk aversion.

Part VI: Three Things That Will Break Your Model

Before building a production system, you need to know the three patterns where each of these models fails.

Adverse selection: When an informed trader hits your quotes, you systematically sell cheap and buy expensive. The metric is the Volume-synchronized Probability of Informed Trading (VPIN):

If VPIN exceeds 0.7 - informed money has entered the market. Widen your spread immediately.

Inventory death spiral: The market maker accumulates a one-sided position and can't get out. The fix is dynamic hedging in a correlated contract. If you're holding $5,000 long in "Trump wins Pennsylvania", buy $2,000 short in "Trump wins Michigan" (high correlation).

Latency arbitrage: Fast bots see a price move in a correlated contract and fill against your stale quote before you can update it. The only defense is speed and leading indicators.

Pre-Launch Checklist

Before running any of this with real money - answer these questions:

1. Do you know Kyle's λ for your contract? Without it, you don't know what trading actually costs you.

1. Have you modeled the order flow? A branching ratio above 0.8 is a danger zone.

1. Do you have hard inventory limits? Without them, the first informed trader will zero you out.

1. Are you computing VPIN in real time? It's your primary early-warning signal.

1. Have you tested resolution? A simulation without modeling the final binary payoff is incomplete.

If you answered no to any of these - don't trade real money.

References

  • Kyle, A.S. (1985). "Continuous Auctions and Insider Trading." *Econometrica*
  • Avellaneda, M. & Stoikov, S. (2008). "High-frequency trading in a limit order book." *Quantitative Finance*
  • Almgren, R. & Chriss, N. (2001). "Optimal execution of portfolio transactions." *Journal of Risk*
  • Hawkes, A.G. (1971). "Spectra of some self-exciting and mutually exciting point processes." *Biometrika*
  • Easley, D. et al. (2012). "Flow Toxicity and Liquidity in a High-frequency World." *Review of Financial Studies*
  • Glosten, L. & Milgrom, P. (1985). "Bid, Ask, and Transaction Prices in a Specialist Market." *JFE*
  • Farmer, Patelli & Zovko (2005). "The Predictive Power of Zero Intelligence." *PNAS*