Market Microstructure & OHLCV Data
Where prices actually come from — the markets, the players, the data we record, and the mechanics of what happens the instant you press BUY.
Why financial markets exist
A financial market is simply a place — today almost always an electronic exchange — where buyers and sellers meet to trade assets. Markets are not background scenery for a quant; they are the environment your strategy lives in, and every edge you find is really a statement about how this environment behaves.
- Capital allocation — channel savings toward companies and projects that can use them.
- Price discovery — aggregate everyone's information into a single, continuously updated price.
- Liquidity — let participants convert assets to cash (and back) quickly and cheaply.
- Risk transfer — move risk from those who want to avoid it (hedgers) to those willing to bear it (speculators).
Quant trading is profitable precisely because these jobs are done imperfectly: prices briefly drift from fair value, liquidity dries up at the wrong moment, and information takes time to spread. Those frictions are the raw material of alpha.
Market participants
Every price is the outcome of many different players with conflicting goals and time horizons. Knowing who is on the other side of your trade is the first step in microstructure.
Retail
Individual investors trading their own money through apps and brokers. Small size, less informed flow.
Institutions
Pension funds, mutual funds and asset managers moving large, slow, long-horizon positions.
Hedge funds
Active speculators chasing returns with leverage and varied strategies, including quant funds.
Market makers
Quote both bid and ask continuously, earning the spread for supplying liquidity.
HFT firms
Ultra-fast automated traders competing on microseconds — often the market makers of modern venues.
Brokers
Intermediaries that route client orders to exchanges; they connect participants to the venue.
A useful split: makers post resting orders and wait (market makers, patient institutions), while takers hit existing quotes for immediate execution (impatient hedge funds, retail). Makers are paid the spread; takers pay it.
Asset classes
The same microstructure ideas apply across markets, but each asset class has its own quirks of liquidity, hours and instruments.
| Asset class | What trades | Notes for a quant |
|---|---|---|
| Equities | Company shares (stocks) | Most studied; deep, centralized, well-documented data. |
| Fixed income | Government & corporate bonds | Often over-the-counter; pricing is yield-driven. |
| FX | Currency pairs (e.g. EUR/USD) | Largest market by volume; trades nearly 24 hours. |
| Commodities | Oil, gold, grains, metals | Strong seasonality and physical-delivery rules. |
| Derivatives | Futures, options, swaps | Value derived from an underlying; key for hedging and leverage. |
| Crypto | Bitcoin, Ether, tokens | 24/7, fragmented venues, high volatility. |
OHLCV data
Raw markets produce a continuous stream of individual trades. To make this tractable, we bucket trades into time bars (one minute, one hour, one day) and summarize each bucket with five numbers: OHLCV. This is the most common format you will load in any backtest.
Open
The first traded price in the bar's time window.
High
The highest price traded during the window.
Low
The lowest price traded during the window.
Close
The final traded price before the window ends.
Volume
Total quantity traded — a proxy for activity and liquidity.
Timestamp
The bar's interval, so bars line up into a time series.
Volume is the number of units (shares, contracts, coins) traded in the bar. High volume usually signals genuine interest and better liquidity, meaning you can trade larger size with less price disruption. Low-volume bars are easy to push around and their prices are less reliable.
| Time | Open | High | Low | Close | Volume |
|---|---|---|---|---|---|
| 09:30 | 100.00 | 100.40 | 99.80 | 100.25 | 12,400 |
| 09:31 | 100.25 | 100.60 | 100.10 | 100.15 | 9,800 |
| 09:32 | 100.15 | 100.30 | 99.90 | 99.95 | 15,200 |
Notice each bar's Open equals the previous Close only approximately — gaps appear when trading is thin or news hits between bars. Real trading systems store millions of these rows; they are the input to nearly every signal you will build.
Microstructure: what happens when you press BUY
OHLCV is a summary. Underneath it sits the order book — the live list of every resting buy and sell order. When you press BUY with a market order, you are not buying from "the market" in the abstract; you are matched against the cheapest resting sell orders until your quantity is filled.
- Bid — the highest price any buyer is currently willing to pay.
- Ask (offer) — the lowest price any seller is currently willing to accept.
- Spread — the gap between them, $\text{Ask}-\text{Bid}$. You buy at the ask and sell at the bid, so the spread is a transaction cost you pay just to round-trip.
A market BUY "crosses the spread": it lifts the best ask. The diagram below traces that match.
flowchart TD
U([You press BUY]) --> M{Order type}
M -->|Market order| X([Cross the spread])
M -->|Limit order| R([Rest in book])
X --> A([Match best Ask])
A --> F([Filled immediately])
R --> W([Wait at your price])
W -.->|Seller arrives| F
classDef s fill:#eef2ff,stroke:#4f46e5,stroke-width:1px,color:#3730a3;
classDef d fill:#ecfdf5,stroke:#0d9488,color:#0d9488;
class U,M,X,R,A,W s
class F d
A market BUY is matched against resting sell orders at the best ask; a limit BUY instead waits in the book until a seller meets its price.
The bid, ask and mid price
From the top of the book we derive the prices quants quote constantly. The mid price is the fair-value reference; the spread measures the cost of immediacy.
Quoting the spread in basis points (1 bp $= 0.01\%$) lets you compare a \$0.10 spread on a \$100 stock against a \$5 spread on a \$5,000 stock fairly: it normalizes by price.
- The book shows Bid $=\$100.10$ and Ask $=\$100.20$.
- Spread: $\text{Spread}=100.20-100.10=\$0.10$.
- Mid: $\text{Mid}=\dfrac{100.10+100.20}{2}=\$100.15$.
- In bps: $\dfrac{0.10}{100.15}\times 10000 \approx 9.99$.
Liquidity, order types & slippage
Liquidity is the ability to trade size without moving the price significantly. A liquid market has tight spreads and deep resting orders at each level, so a large order can be absorbed; an illiquid market lurches on the same order.
How you interact with the book is your choice of order type, and it is a direct trade-off between speed and price.
Market order
Execution priority. Trade now at whatever prices are available. You cross the spread and accept the cost of immediacy. Fill is guaranteed; price is not.
Limit order
Price priority. Specify the worst price you will accept; the order rests in the book until matched. Price is guaranteed; the fill is not (it may never trade).
A large market order eats through the best level, then the next, then the next — it walks the book. Slippage is the gap between the price you expected (the quote) and the average price you actually got. Market impact is your own order pushing the price against you. Both grow with order size and shrink with liquidity, which is why big institutions slice orders into small pieces.
Why a big order costs more than the quote
Suppose only part of your desired size sits at the best ask. The rest fills at worse prices deeper in the book, raising your average cost.
- You want to buy 1,000 shares. The quote (best ask) is \$100.20.
- Only 500 shares are available at \$100.20; the next 500 rest at \$100.30.
- Total cost: $500\times100.20 + 500\times100.30 = 50100 + 50150 = \$100{,}250$.
- Average fill: $\dfrac{100{,}250}{1000}=\$100.25$.
- Slippage vs the \$100.20 quote: $100.25-100.20=\$0.05$ per share.
Self-check: What does OHLCV stand for, and which value is the liquidity proxy?
Self-check: Which order type guarantees execution, and what do you give up for it?
Self-check: Bid \$50.00, Ask \$50.10. What is the spread in bps?
Key takeaways
- Markets exist for capital allocation, price discovery, liquidity and risk transfer; their imperfections are where alpha lives.
- OHLCV bars summarize raw trades: Open / High / Low / Close prices plus Volume (the liquidity proxy).
- Underneath sits the order book: Bid (best buyer), Ask (best seller), Spread $=$ Ask $-$ Bid is a transaction cost, Mid $=$ their average.
- Market orders take liquidity (execution priority); limit orders provide it (price priority).
- Large orders walk the book, causing slippage and market impact — execution quality is part of the strategy, not an afterthought.