Class FairValueEngine

java.lang.Object
com.quantfinlib.pricing.FairValueEngine

public final class FairValueEngine extends Object
Latency-adjusted fair value for rapidly updating order books. Maintains the size-weighted microprice plus a short-window mid drift estimate, so a consumer that is latencyNanos behind the market can project the "true mid" at the moment its order would actually arrive.

Zero allocation after construction (fixed ring of samples); single writer.

  • Constructor Summary

    Constructors
    Constructor
    Description
    256-sample ring over a 500 ms drift window.
    FairValueEngine(int capacity, long windowNanos)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Estimated mid drift in price units per second over the lookback window.
    double
    latencyAdjustedFair(long latencyNanos)
    Fair price projected latencyNanos into the future: microprice plus drift over the latency horizon.
    double
    Latest microprice (NaN before the first quote).
    static double
    microprice(double bid, double ask, double bidSize, double askSize)
    Size-weighted microprice: I*ask + (1-I)*bid, I = bidSize/(bidSize+askSize).
    void
    onQuote(double bid, double ask, double bidSize, double askSize, long timestampNanos)
    Feed a top-of-book update.

    Methods inherited from class java.lang.Object

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

    • FairValueEngine

      public FairValueEngine(int capacity, long windowNanos)
      Parameters:
      capacity - ring capacity (rounded up to a power of two)
      windowNanos - lookback window for the drift estimate
    • FairValueEngine

      public FairValueEngine()
      256-sample ring over a 500 ms drift window.
  • Method Details

    • onQuote

      public void onQuote(double bid, double ask, double bidSize, double askSize, long timestampNanos)
      Feed a top-of-book update.
    • microprice

      public static double microprice(double bid, double ask, double bidSize, double askSize)
      Size-weighted microprice: I*ask + (1-I)*bid, I = bidSize/(bidSize+askSize).
    • microprice

      public double microprice()
      Latest microprice (NaN before the first quote).
    • driftPerSecond

      public double driftPerSecond()
      Estimated mid drift in price units per second over the lookback window.
    • latencyAdjustedFair

      public double latencyAdjustedFair(long latencyNanos)
      Fair price projected latencyNanos into the future: microprice plus drift over the latency horizon.