Class BookAnalytics

java.lang.Object
com.quantfinlib.orderbook.BookAnalytics

public final class BookAnalytics extends Object
Spread, depth and liquidity analytics over an OrderBook: quoted spread, size-weighted microprice, depth imbalance, depth-within-bps, and non-destructive book sweep simulation (VWAP-to-fill and impact of a large marketable order).
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    Result of simulating a sweep: what a marketable order of that size would pay.
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    depthWithinBps(OrderBook book, Side side, double bps)
    Resting quantity on a side priced within bps of the mid.
    static double
    imbalance(OrderBook book, int levels)
    Depth imbalance in [-1, 1] over the top levels: +1 = all bid.
    static double
    microprice(double bid, double ask, double bidSize, double askSize)
     
    static double
    Size-weighted microprice: I*ask + (1-I)*bid with I = bidSize / (bidSize + askSize) — a better short-horizon fair value than the mid when the book is imbalanced.
    static double
     
    sweep(OrderBook book, Side takerSide, long quantity)
    Simulates (without mutating the book) sweeping quantity with a marketable order on takerSide: returns achievable fill, VWAP fill price, and impact versus the pre-sweep mid.

    Methods inherited from class java.lang.Object

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

    • spreadBps

      public static double spreadBps(OrderBook book)
    • microprice

      public static double microprice(OrderBook book)
      Size-weighted microprice: I*ask + (1-I)*bid with I = bidSize / (bidSize + askSize) — a better short-horizon fair value than the mid when the book is imbalanced.
    • microprice

      public static double microprice(double bid, double ask, double bidSize, double askSize)
    • imbalance

      public static double imbalance(OrderBook book, int levels)
      Depth imbalance in [-1, 1] over the top levels: +1 = all bid.
    • depthWithinBps

      public static long depthWithinBps(OrderBook book, Side side, double bps)
      Resting quantity on a side priced within bps of the mid.
    • sweep

      public static BookAnalytics.SweepResult sweep(OrderBook book, Side takerSide, long quantity)
      Simulates (without mutating the book) sweeping quantity with a marketable order on takerSide: returns achievable fill, VWAP fill price, and impact versus the pre-sweep mid.