Market microstructure#
Screamer ships a set of operators that read the trade and order-flow tape: who is trading, how their flow moves price, and how liquid the market is. They turn a raw stream of trades into the signals that short-horizon models are built on. Like every screamer operator they are causal and run in the C++ core.
This page maps out what is available and shows a typical use. For each operator's exact signature and formula, follow its link to the reference page; for full worked examples on real data, see the two notebooks linked at the end.
What's here#
The operators group by what they measure.
Signing trades recovers whether each trade was buyer- or seller-initiated, which a public tape usually does not tell you:
TickRuleSign: the tick rule, from price changes alone.LeeReadySign: the Lee-Ready quote test with a tick-rule fallback, when a mid-quote is available.SignedVolume: a sign times size, giving aggressor-signed order flow.BulkVolumeClassifier: the buy-initiated share of a bar from its return and volatility, with no per-trade signs.
Order-flow imbalance measures net buying pressure, the standard short-horizon driver of price:
OFI: normalized imbalance,(buy - sell) / (buy + sell).RollingOrderImbalance: the trailing sum of signed flow.QueueImbalance: the same normalized imbalance applied to the resting L1 book sizes rather than to trade flow.VPIN: order-flow toxicity, the average one-sidedness of flow over a volume clock (Easley-Lopez de Prado-O'Hara).ContOFI: the canonical order-book-event OFI from L1 quote changes (Cont-Kukanov-Stoikov).
Price impact and liquidity measure how far flow moves price and what trading costs:
RollingKyleLambdaandEwKyleLambda: Kyle's lambda, the price move per unit of signed flow.AmihudIlliquidity: price move per dollar traded, comparable across assets.RollSpread: the effective bid-ask spread implied by trade prices.EffectiveSpreadandRealizedSpread: the round-trip cost paid, and the part of it the liquidity provider keeps after the price moves (their difference is the price-impact / adverse-selection component).Propagator: the Bouchaud model, where impact builds and then relaxes through a decaying kernel.MicroPrice: an imbalance-weighted fair value that leans toward the thinner side of the book (Stoikov).
Event intensity measures the clustering of activity:
HawkesIntensity: a self-exciting arrival rate, where each trade briefly raises the expected rate of the next.
A typical use case#
Start from a trade tape (price and size per trade, with timestamps), sign each trade, turn it into signed order flow, aggregate the flow into bars, and estimate the price impact of that flow:
import numpy as np
from screamer import TickRuleSign, SignedVolume, RollingKyleLambda, Resample, LogReturn
# price, size, and millisecond timestamps, one row per trade
sign = TickRuleSign()(price) # +1 buyer-initiated, -1 seller-initiated
flow = SignedVolume()(sign, size) # aggressor-signed order flow
# one-minute bars: net signed flow and the bar's close-to-close return
net, _ = Resample(freq=60_000, agg="sum")(flow, ts)
close, idx = Resample(freq=60_000, agg="last")(price, ts)
ret = LogReturn(1)(close)
# price impact: the slope of return on signed flow, over a trailing window
kyle_lambda = RollingKyleLambda(30)(net, ret)
Worked examples#
Two notebooks work these models end to end on a real slice of Deribit trades:
Order flow and trade signing: infer the trade sign with the tick rule and check it against the venue's true aggressor sign, then build signed volume, order-flow imbalance, rolling imbalance, and trade-arrival intensity.
Price impact and liquidity: estimate Kyle's lambda, Amihud illiquidity, the Roll spread, and the Bouchaud propagator, and compare liquidity across BTC and ETH.
For the complete list with signatures and formulas, see the Microstructure function index.