Class Vpin

java.lang.Object
com.quantfinlib.microstructure.Vpin

public final class Vpin extends Object
VPIN — Volume-synchronized Probability of INformed trading (Easley, López de Prado & O'Hara): the flow-toxicity gauge a market maker watches to decide when quoting is no longer a business. Trades fill fixed-VOLUME buckets (volume time, not clock time — informed trading compresses clock time but not volume time); each full bucket scores its absolute buy/sell imbalance; VPIN is the average over the last window buckets:
  VPIN = (1/n) Σ |buyVol − sellVol| / bucketVolume

Balanced two-way flow reads near 0; one-sided (informed) flow reads toward 1 — famously elevated in the hour before the 2010 flash crash. Feed it TradeClassifier's aggressor sides when the venue does not disclose them. A trade larger than the bucket's remaining capacity SPLITS across buckets, as the original construction requires. Deterministic, O(1) per trade, allocation only at construction; research/warm lane.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Vpin(long bucketVolume, int window)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    void
    onTrade(long quantity, boolean buyAggressor)
    One classified trade.
    boolean
    True once the full window of buckets has completed.
    double
    The toxicity estimate over completed buckets; NaN until the first bucket completes (an empty average pretending to be calm would be exactly the wrong default for a risk signal).

    Methods inherited from class java.lang.Object

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

    • Vpin

      public Vpin(long bucketVolume, int window)
      Parameters:
      bucketVolume - shares/contracts per volume bucket, > 0 (the classic choice: ~1/50th of average daily volume)
      window - completed buckets averaged, ≥ 1 (classic: 50)
  • Method Details

    • onTrade

      public void onTrade(long quantity, boolean buyAggressor)
      One classified trade. Splits across bucket boundaries as needed.
      Parameters:
      quantity - traded volume, > 0
      buyAggressor - true if the buyer was the aggressor
    • vpin

      public double vpin()
      The toxicity estimate over completed buckets; NaN until the first bucket completes (an empty average pretending to be calm would be exactly the wrong default for a risk signal).
    • ready

      public boolean ready()
      True once the full window of buckets has completed.
    • bucketsCompleted

      public int bucketsCompleted()