Depth-Weighted Midprice
Install and import
npm install fintech-algorithmsimport { depthWeightedMidprice } from "fintech-algorithms/market-microstructure/order-book-dynamics/depth-weighted-midprice";Signature
depthWeightedMidprice(bidPrices, bidSizes, askPrices, askSizes)A midpoint weighted by depth across several levels rather than the naive average of best bid and ask. Less prone to jumping when a single small order sits at the touch.
Parameters
| Name | Type | Notes |
|---|---|---|
bidPrices | number[] | Bid prices, best first. |
bidSizes | number[] | Sizes aligned with bidPrices. |
askPrices | number[] | Ask prices, best first. |
askSizes | number[] | Sizes aligned with askPrices. |
Returns
{ midprice, simple_midpoint, weighted_bid, weighted_ask, … }
The depth-weighted midpoint alongside the naive one, so the difference is visible.
Errors
- When total depth on either side is zero — throws
Complexity: time O(levels),
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.99, 99.98, 99.97][500, 1000, 1500][100.01, 100.02, 100.03][300, 700, 2000]Call
depthWeightedMidprice(bidPrices, bidSizes, askPrices, askSizes)Returns
object with 13 fields: model, level_count, bid_level_count, ask_level_count, top_midpoint, depth_weighted_bid, depth_weighted_ask, depth_weighted_midprice, …
{
"model": "same-side-depth-weighted-midpoint",
"level_count": 3,
"bid_level_count": 3,
"ask_level_count": 3,
"top_midpoint": 100,
"depth_weighted_bid": 99.97666666666667,
"depth_weighted_ask": 100.02566666666667,
"depth_weighted_midprice": 100.00116666666668,
"shift": 0.0011666666666769743,
"shift_bps": 0.11666666666769743,
"bid_total_depth": 3000,
"ask_total_depth": 3000,
"state": "above-top-mid"
}Other exports
This module also exports
orderBookSlope, microprice, 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 microprice paper and explicit package convention — Sasha Stoikov; exact same-side weighting is a repository implementation choice
- NYSE Integrated Feed — NYSE
- Publication and data boundary