VPIN Order-Flow Toxicity in Python: Bulk Volume Classification and the Case Against It

The one question this post answers: can VPIN, computed with Bulk Volume Classification, be trusted as an order-flow toxicity feature, and how do you compute an honest daily-bar proxy of it in Python?
VPIN comes from Easley, López de Prado and O’Hara’s Flow Toxicity and Liquidity in a High-Frequency World, published in the Review of Financial Studies 25(5):1457–1493. Its companion working paper, Bulk Classification of Trading Activity (SSRN 1989555), supplies the classifier implemented below.
Trust note. The critiques are presented alongside the original claims, and the authors’ patent application and financial interest are disclosed below.
What Order-Flow Toxicity Is — and Why It Matters
Order-flow toxicity is the risk that informed, one-sided flow picks off liquidity providers who quote both sides of the book. Easley, López de Prado and O’Hara built VPIN to measure it, arguing the metric is updated in volume time, which makes it applicable to the high-frequency world (Flow Toxicity and Liquidity in a High-Frequency World).
Volume Time — How the Original VPIN Buckets Trades
The original VPIN runs on volume time: trades fill equal-volume buckets of size V, set to one-fiftieth of average daily volume, with n = 50 buckets. VPIN is recomputed after each bucket, and when bucket 51 fills, bucket 1 is dropped (Flow Toxicity and Liquidity in a High-Frequency World).
The Tick Rule — The Baseline Classifier
A trade is classified as a buy when its price exceeds the previous trade price, a sell when lower, and an equal price inherits the prior side. That is the tick rule, the baseline any bulk method must beat (Bulk Classification of Trading Activity).
Bulk Volume Classification — The Formula Behind BVC
BVC splits a bar’s volume by the standardized price change between consecutive bar closes. V^B = V·Φ(ΔP/σ_ΔP) is buy volume, V^S = V − V^B is sell volume, and Φ is the standard normal CDF. The authors note the i.i.d.-normal assumption is a simplification (Bulk Classification of Trading Activity).
dP_tau = Close_tau - Close_(tau-1)
sigma_dP = standard deviation of dP (i.i.d. normal assumption)
V^B_tau = V_tau * Phi(dP_tau / sigma_dP) # buy volume
V^S_tau = V_tau - V^B_tau # sell volume
VPIN = (1/n) * sum over the last n buckets of |V^S - V^B| / V
The working paper’s appendix contains the authors’ Python code, visible in a full-text mirror of SSRN 1989555. The mirror is supplementary; the canonical record is the SSRN DOI.
The Authors’ Evidence — BVC vs the Tick Rule on Futures
The authors’ patent application and financial interest in the method apply to every figure below. The paper tests three futures: e-mini S&P 500, WTI crude and gold, over a sample running from about November 2010 to November 2011. On the e-mini, the tick rule classifies 86.43% of volume correctly. BVC reaches 91.00% with 8,000-contract volume bars, the best volume-bar result in its Table 1, and 87.60% with the best time-bar setting (Bulk Classification of Trading Activity).
The paper is internally inconsistent on the other two contracts. Its introduction gives 91.59% for oil and 87.36% for gold, with tick-rule shares of 78.95% for oil and 67.18% for gold. Its Section 3.4 and the Table 2–3 panels pair the figures the other way: WTI tick 67.18% against BVC about 87% on volume bars, and gold tick 78.95% against BVC above 91% on volume bars (same source). Quote the tables, and flag the introduction’s labelling if you cite it.
The chosen bar specs, per Section 4: e-mini 2-minute time bars or 8,000-contract volume bars; WTI 5-minute time bars with 5,000-contract volume bars; gold 5-minute time bars with 4,500-contract volume bars. Volume bars beat the tick rule on 99.19% of e-mini days, and time bars on 82.11% (same source). BVC does not win everywhere: at the shortest bar size in Table 1 it trails the tick rule, 74.05% against 86.43%, and the paper reports that all three methods degrade on the most active days, including 9 August 2011 (same source).
The paper reports three caveats: classification accuracy dips around futures roll dates, which the authors recommend excluding; the tick rule degrades in less liquid contracts; and BVC degrades on very active days (same source). One-minute e-mini BVC used 0.35% of the original tick dataset (same source).
VPIN in Python — A Daily-Bar Proxy
You can compute a VPIN-shaped proxy from public daily OHLCV: classify each day’s volume with BVC using the standardized close-to-close change over a trailing window, treat one trading day as one bucket, and average |V^S − V^B|/V over the trailing 50 days. Label the result a PROXY, because the paper uses intraday bars (Bulk Classification of Trading Activity).
import numpy as np
import pandas as pd
from math import erf, sqrt
def vpin_daily_proxy(df: pd.DataFrame, n: int = 50) -> pd.Series:
"""
Bulk Volume Classification + rolling VPIN proxy on PUBLIC DAILY bars.
PROXY: the paper (SSRN 1989555) classifies INTRADAY time bars or volume
bars. Here one trading day = one bucket, so this is a daily-bar VPIN
*proxy* -- NOT the paper's intraday VPIN. Output is illustrative only.
df : daily OHLCV frame with 'Close' and 'Volume' columns
(e.g., pulled with yfinance or the blog's get-prices.py helper).
n : number of trailing buckets averaged into VPIN (paper uses n = 50).
"""
vol = df["Volume"].where(df["Volume"] > 0) # zero-volume days -> NaN, not inf
dP = df["Close"].diff() # dP_t = C_t - C_{t-1}
sigma = dP.rolling(n, min_periods=20).std() # trailing std of price changes
# BVC (SSRN 1989555, eq. 1): V_buy = V * Phi(dP / sigma); V_sell = V - V_buy
z = np.clip((dP / sigma).to_numpy(), -8.0, 8.0)
Phi = np.vectorize(lambda x: 0.5 * (1.0 + erf(x / sqrt(2.0)))) # std normal CDF
v_buy = vol.to_numpy() * Phi(z)
v_sell = vol.to_numpy() - v_buy
# Bucket imbalance |V^S - V^B| / V, then VPIN = (1/n) * sum over last n buckets
imbalance = pd.Series(np.abs(v_sell - v_buy), index=df.index) / vol
return imbalance.rolling(n).mean() # the 50-day VPIN proxy
Daily bars are a PROXY for the paper’s intraday bars. The docstring assumes an OHLCV frame, such as one pulled with yfinance. A daily close-to-close change compresses a whole session into one standardized number, so this output does not reproduce the paper’s measure, and its levels are not comparable to published VPIN readings.
The Claim That Made VPIN Famous — The Flash Crash
Easley, López de Prado and O’Hara reported VPIN at historically high readings in the hours before the 6 May 2010 flash crash, arguing elevated toxicity contributed to liquidity providers withdrawing (Flow Toxicity and Liquidity in a High-Frequency World).
Andersen and Bondarenko contest the timing and the predictive story, and a separate perfect-classification test is harsher still. Treat the flash-crash narrative as contested. The regulators’ own account is the SEC/CFTC staff report on the 6 May 2010 market events, with preliminary findings on the CFTC staff-report page; both are cited here for the event date only, because neither was read in full.
The Case Against, Part 1 — Andersen & Bondarenko
Andersen and Bondarenko find VPIN is a poor predictor of short-run volatility, that it did not reach an all-time high before but rather after the flash crash, and that its predictive content comes primarily from a mechanical relation with trading intensity (VPIN and the Flash Crash). We retrieved the CREATES working paper and checked the quoted lines against it. Its abstract states VPIN “did not reach an all-time high prior, but rather after, the flash crash” — a direct collision with the original claim, in a working paper later published in the Journal of Financial Markets (2014) (RePEc record).
The Case Against, Part 2 — Perfect Trade Classification
Using CME BBO files to benchmark against perfect classification, Bondarenko finds BVC inferior to a standard tick rule. BVC’s forecast power for volatility comes from systematic classification errors correlated with trading volume and volatility; controlling for those, BVC-VPIN has no incremental predictive power (Assessing VPIN Measurement of Order Flow Toxicity via Perfect Trade Classification (abstract listing)).
This rests on the abstract listing, so the claim is limited to what the abstract supports. Its conclusion is blunt: VPIN “is not suitable for capturing order flow toxicity.”
The Case Against, Part 3 — The Horse Race on Equities
A 2015 Journal of Financial Markets horse race on a large equity sample finds the tick rule and Lee-Ready produce significantly better classifications than BVC. Iteratively optimizing BVC helps, but conventional rules still outperform, and their order imbalances stay comparable to BVC’s for explaining returns, liquidity and trading costs (Evaluating trade classification algorithms (abstract listing)). We read this as an abstract listing, and the authors are not named because we could not verify them.
Here is the comparison across the three classifiers. Empty cells mean our sources report nothing.
| Tick rule | BVC | Lee-Ready | |
|---|---|---|---|
| Rule | Buy if price exceeds prior trade price; sell if lower; equal inherits prior side | V^B = V·Φ(ΔP/σ_ΔP); V^S = V − V^B per bar | Quote rule away from the BBO midpoint; tick rule at the midpoint (SSRN 1989555, §1.3) |
| e-mini S&P 500 volume correct | 86.43% | 91.00% (8,000-contract volume bars); 87.60% best time-bar setting (same source, Table 1) | Not reported in our sources |
| WTI and gold volume correct | WTI 67.18%; gold 78.95% (Section 3.4, Tables 2–3; the introduction pairs them differently) | WTI about 87% and gold above 91% on volume bars (Section 3.4) | Reduces to the tick rule for futures (same source, footnote 7) |
| Equity accuracy, as reported | Odders-White (NYSE, 1991): 78.6%; Ellis et al. (Nasdaq, late 1990s): 80% | Not reported in our sources | Odders-White: 85%; Ellis et al. (Nasdaq, 1996): 83%; Chakrabarty et al. (INET, 2005): 68–69% (same source, §1) |
| Bar specs used | Not applicable — trade-by-trade | Chosen: e-mini 2-min time / 8,000-contract volume; WTI 5-min / 5,000; gold 5-min / 4,500 | Not applicable — trade-by-trade |
| Equity horse race (2015) | Significantly better classifications than BVC | Significantly worse; improves with iteration, still outperformed | Significantly better than BVC |
| Perfect-classification test, CME BBO | Standard tick rule judged superior to BVC | Inferior; volatility forecast power attributed to systematic errors | Not tested in our sources |
| Data cost | Trade-by-trade prices | Bar closes and volume; 1-minute e-mini bars used 0.35% of the tick dataset | Level 2 data (quotes and trades) required (same source, §1.3) |
Futures figures and bar specs: Bulk Classification of Trading Activity. Perfect-classification row: abstract listing. Equity horse race row: abstract listing.
Where the Debate Stands — A Rejoinder and a Follow-Up
Easley et al. published a rejoinder, “VPIN and the Flash Crash: A rejoinder” (Journal of Financial Markets, 2014). In a later paper they argue tick-rule approaches and BVC are relatively good classifiers of the aggressor side, though bulk classifications link better to proxies of information-based trading (Discerning information from trade data (abstract listing)). We have the rejoinder’s title and venue only, so no content claims are made about it.
Limits — What a Daily-Bar VPIN Proxy Can and Cannot Tell You
- Daily-bar proxy. One trading day per bucket and a 50-day trailing window is not the paper’s intraday measure. Levels are not comparable to published VPIN values; label it PROXY everywhere it appears.
- Patent disclosure. The authors applied for a patent on Bulk Volume Classification and have a financial interest in it, disclosed on the first page of the SSRN paper. Restate it whenever their accuracy numbers are cited.
- Bar-spec dependence, roll dates and internal inconsistency. BVC accuracy depends on bar spec and dips around futures roll dates, and the paper’s own introduction and tables disagree on which contract gets which figures (same source).
- A rejoinder exists. Its title and venue are noted above; its body was not read.
FAQ
Is a daily-bar VPIN the same as the paper’s VPIN?
No. The original VPIN buckets trades into equal-volume buckets of one-fiftieth of average daily volume and updates after every bucket (Flow Toxicity and Liquidity in a High-Frequency World). A daily-bar version treats each trading day as one bucket and averages standardized imbalances over 50 days. It is a labelled proxy, and its levels should never be compared with published VPIN readings.
Did VPIN predict the flash crash?
The original authors say VPIN was at historically high readings in the hours before 6 May 2010 (Flow Toxicity and Liquidity in a High-Frequency World). Andersen and Bondarenko counter that it hit its all-time high after the crash and is a poor short-run volatility predictor whose content reflects trading intensity (VPIN and the Flash Crash). Treat it as contested, not settled.
Is BVC more accurate than the tick rule?
It depends on the sample and bar spec. On the e-mini, BVC’s best volume-bar setting reaches 91.00% against the tick rule’s 86.43%. On gold, Section 3.4 reports tick 78.95% against more than 91% for BVC on volume bars (Bulk Classification of Trading Activity). An independent horse race on equities finds the tick rule and Lee-Ready significantly better, with iterated BVC still losing (Evaluating trade classification algorithms (abstract listing)).
The Bottom Line
VPIN is best treated as a research feature with a contested interpretation. The sourced parts: BVC’s futures advantage is real but bar-spec-dependent, internally inconsistent in its contract-level reporting, and self-reported by authors with a patent application and financial interest (Bulk Classification of Trading Activity); independent tests find conventional classifiers at least as good (perfect-classification abstract, horse-race abstract), though a later Easley et al. abstract in the Journal of Financial Economics (2016) finds BVC better linked to information-based trading proxies (abstract listing); and Andersen and Bondarenko attribute VPIN’s apparent predictive content to trading intensity (CREATES working paper). Use the daily-bar proxy for exploration and teaching. It is not a validated toxicity oracle and must never be presented as a crash predictor.
How This Guide Was Built
This review is based on official papers, the authors’ published methods, and public daily price data — we did not run the original intraday classification hands-on. We retrieved the full text of the Review of Financial Studies article, the Andersen–Bondarenko working paper and the SSRN 1989555 working paper. We checked the working paper’s introduction, Section 3.4, Tables 1–3 and Section 4 against each other, and the contract pairings disagree, as reported above. The other papers were read as abstract listings only. The Python snippet is an original daily-bar adaptation. The code is illustrative and has not been backtested or validated against tick data; the authors’ appendix code was not run either.
← Back to all posts

