Class FairValueEngine
java.lang.Object
com.quantfinlib.pricing.FairValueEngine
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
ConstructorsConstructorDescription256-sample ring over a 500 ms drift window.FairValueEngine(int capacity, long windowNanos) -
Method Summary
Modifier and TypeMethodDescriptiondoubleEstimated mid drift in price units per second over the lookback window.doublelatencyAdjustedFair(long latencyNanos) Fair price projectedlatencyNanosinto the future: microprice plus drift over the latency horizon.doubleLatest microprice (NaN before the first quote).static doublemicroprice(double bid, double ask, double bidSize, double askSize) Size-weighted microprice:I*ask + (1-I)*bid,I = bidSize/(bidSize+askSize).voidonQuote(double bid, double ask, double bidSize, double askSize, long timestampNanos) Feed a top-of-book update.
-
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 projectedlatencyNanosinto the future: microprice plus drift over the latency horizon.
-