Order-Book Resiliency
Install and import
npm install fintech-algorithmsimport { orderBookResiliency } from "fintech-algorithms/market-microstructure/order-book-dynamics/order-book-resiliency";Signature
orderBookResiliency(timesSeconds, displacementBps, forecastSeconds)How quickly the book refills after being depleted, fitted as a decay over observed displacement. Resiliency is the third dimension of liquidity beside spread and depth, and the one that decides whether a large order can be worked at all.
Parameters
| Name | Type | Notes |
|---|---|---|
timesSeconds | number[] | Observation times after the depleting event, in seconds. |
displacementBps | number[] | Displacement from the pre-event level at each time, in basis points. |
forecastSeconds | number | Horizon at which to project the remaining displacement. min: 0 |
Returns
{ decay_rate, half_life_seconds, forecast_displacement, fit_quality, … }
The decay rate and half-life, with fit quality — a resiliency figure from a poor fit is not usable.
Errors
- When the two series differ in length or contain fewer than two points — throws
Complexity: time O(n),
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
[0, 1, 2, 3, 4, 5]Showing 6 of 7 elements.
[8, 5.637504, 3.972682, 2.7995, 1.972776, 1.390191]Showing 6 of 7 elements.
5Call
orderBookResiliency(timesSeconds, displacementBps, forecastSeconds)Returns
object with 11 fields: model, observation_count, initial_displacement_bps, recovery_rate_per_second, half_life_seconds, forecast_seconds, forecast_displacement_bps, recovered_fraction, …
{
"model": "exponential-displacement-recovery",
"observation_count": 7,
"initial_displacement_bps": 8,
"recovery_rate_per_second": 0.3500000711368042,
"half_life_seconds": 1.980420113369107,
"forecast_seconds": 5,
"forecast_displacement_bps": 1.3901910531347295,
"recovered_fraction": 0.8262261183581588,
"fitted_displacement_bps": [
8,
5.637504316715653,
3.972681865123452,
2.799501395446431,
1.9727751501850936,
1.3901910531347295
],
"rmse_bps": 6.314204089006822e-7,
"state": "estimated"
}Other exports
This module also exports
orderBookSlope, depthWeightedMidprice, microprice, 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
- Obizhaeva and Wang (2013) — Anna A. Obizhaeva and Jiang Wang
- NYSE Integrated Feed — NYSE
- Publication and data boundary