What's inside
The library covers the core building blocks of order-flow and execution analysis — the same primitives behind our market microstructure analytics and quantitative research.
| Family | What it computes |
|---|---|
| Order Flow Imbalance | Level-1 OFI (Cont–Kukanov–Stoikov), per-step and cumulative |
| Imbalance | Top-of-book depth imbalance and trade imbalance |
| VPIN | Flow toxicity via volume bucketing and bulk-volume classification |
| Information-driven bars | Tick, volume, and dollar bars |
| Execution / TCA | Effective & realized spread, price impact, Kyle's lambda, Roll's estimator |
| Fair value | Mid, imbalance-weighted micro-price, relative spread (bps) |
| Trade-sign classification | Tick rule and Lee-Ready |
| Liquidity & volatility | Amihud illiquidity, realized & annualized volatility |
| Market efficiency | Autocorrelation and the Lo-MacKinlay variance ratio |
| Hurst exponent | Long memory — trend vs mean reversion via rescaled range (R/S) |
| Range-based volatility | Parkinson, Garman-Klass, Rogers-Satchell, Yang-Zhang (from OHLC) |
| Realized moments | Realized skewness and kurtosis of intraday returns |
| Jumps & bipower variation | Separate jumps from continuous volatility (Barndorff-Nielsen–Shephard) |
| Realized semivariance | Upside / downside variance split and signed jump variation |
| Order-flow entropy | Shannon, normalized and sign entropy of order flow |
| Online / streaming estimators | Welford, EWMA / RiskMetrics variance, O(1) rolling windows |
| Cross-asset | Realized covariance, correlation and beta from aligned returns |
| Spread estimators (OHLC) | Corwin-Schultz and Abdi-Ranaldo effective-spread estimators |
| Market impact & markouts | Square-root & Almgren-Chriss impact, implementation shortfall, trade markouts |
| Order book | Reconstruction from incremental updates; depth and imbalance |
| Market-order simulation | Sweep the book for VWAP fill, slippage, and unfilled size |
| Execution scheduling | TWAP and percentage-of-volume slicers |
Install & use
Python — published on PyPI:
pip install orderflow-metrics
from orderflow_metrics import ofi, dollar_bars, vpin bars = dollar_bars(trades, 250_000) # sample by activity, not the clock signal = ofi(quotes) # net top-of-book pressure toxicity = vpin(bucket_by_volume(trades, 1_000))
TypeScript — published on npm as compiled ESM with type declarations (zero runtime dependencies, Node ≥ 18). You can also read or vendor the TypeScript src/ directly from GitHub:
npm install orderflow-metrics
import { ofi, dollarBars, vpin } from "orderflow-metrics";
Why we open-source it
Good microstructure primitives shouldn't be a black box. Publishing them cleanly — dependency-free, tested, and documented — is how we think trading technology should be built: legible, verifiable, and reusable. The library is also the sampling and signal layer that our infrastructure and research build on. It is educational and technical material only — not investment advice.