Class TradeClassifier
java.lang.Object
com.quantfinlib.microstructure.TradeClassifier
Trade aggressor classification (Lee-Ready, 1991): the missing glue for
feeds that print trades without saying who initiated.
FlowSignals
and SignalEngine.onTrade need buyAggressor; consolidated
tapes and many FX feeds don't carry it, so it must be inferred:
- Quote rule — a trade at or above the ask was buyer-initiated (someone lifted the offer); at or below the bid, seller-initiated. Between the quotes, above the mid leans buy, below leans sell;
- Tick test (exactly at the mid, or no quote) — an uptick from the previous trade price is a buy, a downtick a sell, an equal price repeats the last classification (the "zero-tick" rule).
Classification accuracy of this scheme is ~85% on modern equity data and similar on FX ECN prints — imperfect by construction (that's the literature's number, not a defect), which is why the imbalance signals it feeds are exponentially decayed averages rather than per-trade truths. One instance per symbol; cross-asset (raw double prices); zero allocation, single writer.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintclassify(double tradePrice) Classifies a trade print and remembers it for the tick test.booleanisBuyAggressor(double tradePrice) Convenience forSignalEngine.onTrade: UNKNOWN maps to the last known side.voidonQuote(double bid, double ask) The current inside quote (NaN sides are treated as absent).
-
Field Details
-
BUY
public static final int BUYClassification results.- See Also:
-
SELL
public static final int SELL- See Also:
-
UNKNOWN
public static final int UNKNOWN- See Also:
-
-
Constructor Details
-
TradeClassifier
public TradeClassifier()
-
-
Method Details
-
onQuote
public void onQuote(double bid, double ask) The current inside quote (NaN sides are treated as absent). -
classify
-
isBuyAggressor
public boolean isBuyAggressor(double tradePrice) Convenience forSignalEngine.onTrade: UNKNOWN maps to the last known side.
-