Class Vpin
java.lang.Object
com.quantfinlib.microstructure.Vpin
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 -
Method Summary
Modifier and TypeMethodDescriptionintvoidonTrade(long quantity, boolean buyAggressor) One classified trade.booleanready()True once the full window of buckets has completed.doublevpin()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).
-
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, > 0buyAggressor- 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()
-