Class FlowSignals
java.lang.Object
com.quantfinlib.microstructure.FlowSignals
Streaming order-flow signals for short-horizon execution decisions: the
three imbalances an execution engine reads before crossing a spread —
cross-asset (equity ticks or raw FX rates; see the two onQuote entry
points) —
- Order-flow imbalance (OFI) — Cont/Kukanov/Stoikov best-level formulation: a bid price/size increase or ask decrease is buying pressure; the mirror is selling pressure. Exponentially time-decayed so the signal is a "recent net flow" with a configurable memory;
- Queue imbalance —
(bidSize - askSize)/(bidSize + askSize)at the inside, the classic next-tick-direction predictor; - Trade imbalance — time-decayed signed aggressor volume over time-decayed total volume (+1 = all buying, -1 = all selling).
Zero allocation per event, single-writer, primitives only — feed it
from the same thread as your book builder or bus callback. Microprice
itself lives in pricing.FairValueEngine; these are its flow-side
complements.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleofi()Time-decayed net order-flow imbalance in shares (+ = buying pressure).doubleofi(long nowNanos) Decay-adjusted OFI as ofnowNanoswithout adding an event.voidonQuote(double bid, long bidSz, double ask, long askSz, long timestampNanos) Inside-quote update on raw double prices — the cross-asset entry point (FX rates, or anything not tick-gridded).voidonQuote(int bidTick, long bidSz, int askTick, long askSz, long timestampNanos) Inside-quote update (ticks + sizes).voidonTrade(boolean buyAggressor, long quantity, long timestampNanos) Trade print with aggressor side:buyAggressortrue when the buyer crossed the spread (trade at/above ask under Lee-Ready).doubleInside-queue imbalance in [-1, 1]; 0 when either side is empty/unset.longlongdoubleSigned/total decayed aggressor volume in [-1, 1]; 0 before any trade.
-
Constructor Details
-
FlowSignals
public FlowSignals(long halfLifeNanos) - Parameters:
halfLifeNanos- decay half-life for OFI and trade imbalance; e.g. 500ms =500_000_000L. Shorter = twitchier.
-
FlowSignals
public FlowSignals()500 ms half-life.
-
-
Method Details
-
onQuote
public void onQuote(int bidTick, long bidSz, int askTick, long askSz, long timestampNanos) Inside-quote update (ticks + sizes). The OFI contribution of this event, per the best-level formulation: bid up/size up ⇒ +, bid down ⇒ −, ask down/size up ⇒ −, ask up ⇒ +.One-sided quotes (either size ≤ 0, e.g. an
Nbbosentinel after the last venue on a side drops) and non-dealable prices (NaN, zero, negative, infinite — placeholder sentinels) are treated as a signal GAP: queue imbalance reads 0 and no OFI contribution is booked — a feed artifact must not look like an aggressive sweep. The next two-sided dealable quote re-seeds the OFI baseline. This is the same gateSignalEngineapplies, so both classify identically. -
onQuote
public void onQuote(double bid, long bidSz, double ask, long askSz, long timestampNanos) Inside-quote update on raw double prices — the cross-asset entry point (FX rates, or anything not tick-gridded). Same semantics as the tick overload: price comparisons drive the OFI legs, so any monotonic price representation works. -
onTrade
public void onTrade(boolean buyAggressor, long quantity, long timestampNanos) Trade print with aggressor side:buyAggressortrue when the buyer crossed the spread (trade at/above ask under Lee-Ready). -
ofi
public double ofi()Time-decayed net order-flow imbalance in shares (+ = buying pressure). -
ofi
public double ofi(long nowNanos) Decay-adjusted OFI as ofnowNanoswithout adding an event. -
queueImbalance
public double queueImbalance()Inside-queue imbalance in [-1, 1]; 0 when either side is empty/unset. -
tradeImbalance
public double tradeImbalance()Signed/total decayed aggressor volume in [-1, 1]; 0 before any trade. -
quoteCount
public long quoteCount() -
tradeCount
public long tradeCount()
-