Class TradeClassifier

java.lang.Object
com.quantfinlib.microstructure.TradeClassifier

public final class TradeClassifier extends Object
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:
  1. 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;
  2. 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
    Modifier and Type
    Field
    Description
    static final int
    Classification results.
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    classify(double tradePrice)
    Classifies a trade print and remembers it for the tick test.
    boolean
    isBuyAggressor(double tradePrice)
    Convenience for SignalEngine.onTrade: UNKNOWN maps to the last known side.
    void
    onQuote(double bid, double ask)
    The current inside quote (NaN sides are treated as absent).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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

      public int classify(double tradePrice)
      Classifies a trade print and remembers it for the tick test. Returns BUY, SELL or UNKNOWN (no quote, no prior trade, or a non-finite price).
    • isBuyAggressor

      public boolean isBuyAggressor(double tradePrice)
      Convenience for SignalEngine.onTrade: UNKNOWN maps to the last known side.