fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Microprice

Install and import#

bash
npm install fintech-algorithms
ts
import { 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#

NameTypeNotes
bidnumberBest bid price.
bidSizenumberSize at the best bid.
min: 0
asknumberBest ask price.
askSizenumberSize 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#

bid
99.99
bidSize
800
ask
100.01
askSize
200

Call#

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#

Microprice — system map

Calculation flow#

Microprice validation flow
flowchart LR
    A["Question: How does top-of-book queue imbalance shift a quote-based reference price inside the spread?"] --> B["Reconstruct one causal book or event state"]
    B --> C["Freeze scope, window, sequence, session, units, and variant"]
    C --> D{"Eligible input?"}
    D -- "No" --> E["Reject with topic-specific reason"]
    D -- "Yes" --> F["Apply the frozen Microprice relationship"]
    F --> G["Expose intermediate diagnostics and state"]
    G --> H{"Static identity, fitted proxy, or conditional model?"}
    H --> I["Report output with convention and evidence boundary"]

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.

Read the article →

References#

The rest of the Order-Book Dynamics family#