Microprice
Install and import
npm install fintech-algorithmsimport { microprice } from "fintech-algorithms/market-microstructure/order-book-dynamics/microprice";Signature
microprice(bid, bidSize, ask, askSize)The midpoint weighted by the *opposite* side's size, so a heavy bid pulls the price up. Counter-intuitive until you see the derivation — the imbalance predicts where the midpoint is going, not where it is.
Parameters
| Name | Type | Notes |
|---|---|---|
bid | number | Best bid price. |
bidSize | number | Size at the best bid. min: 0 |
ask | number | Best ask price. |
askSize | number | Size at the best ask. min: 0 |
Returns
{ microprice, midpoint, imbalance, … }
The microprice with the imbalance that tilted it.
Errors
- When both sizes are zero, or ask is below bid — throws
Complexity: time O(1),
space O(1).
Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
99.99800100.01200Call
microprice(bid, bidSize, ask, askSize)Returns
object with 13 fields: model, bid, ask, bid_size, ask_size, midpoint, spread, queue_imbalance, …
{
"model": "top-of-book-imbalance-weighted-quote",
"bid": 99.99,
"ask": 100.01,
"bid_size": 800,
"ask_size": 200,
"midpoint": 100,
"spread": 0.020000000000010232,
"queue_imbalance": 0.6,
"microprice": 100.006,
"shift": 0.006000000000000227,
"shift_bps": 0.6000000000000227,
"identity_error": 0,
"state": "bid-pressure"
}Other exports
This module also exports
orderBookSlope, depthWeightedMidprice, orderBookResiliency, hawkesOrderArrival, calculate. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- Stoikov, The Micro-Price — Sasha Stoikov
- NYSE Integrated Feed — NYSE
- Publication and data boundary