VPIN Example: One Tape, Two Classifiers
On the same synthetic tape, mean VPIN is 0.4410 with bulk volume classification and 0.1779 with the tick rule. The classifier changes the reading substantially, so a VPIN threshold needs more context than a number.
- Reproduction record
- Checked 4 September 2026. Seed:
20260808. - Source
- vpin-order-flow-toxicity at revision
70ae45c. - Environment used
- Python 3.11.9, NumPy 2.4.6, pandas 3.0.5, SciPy 1.17.1.
- Data
- Synthetic. These examples test the implementation and illustrate the method; they do not measure trading performance on real securities.
Set up the experiment
The generator creates 20,000 trades with total volume 5,344,047. A segment with one-sided flow is inserted into an otherwise balanced tape. Both classifiers receive the same trades, bucket size of 21,376 and rolling window of 50 buckets.
Compare the output
| Measure | Bulk volume classification | Tick rule |
|---|---|---|
| Complete buckets | 250 | 250 |
| Mean VPIN | 0.4410 | 0.1779 |
| Minimum | 0.2805 | 0.1247 |
| Maximum | 0.8257 | 0.2918 |
For bulk volume classification, the mean in the balanced segment is 0.3292, compared with 0.6376 in the planted one-sided segment: a ratio of 1.94. This describes the two segments in this tape, not a forecast accuracy or trading return.
The buckets account for 5,344,000 volume units. The remaining 47 units are in an incomplete final bucket and are excluded by design. The console rounds this coverage to 100.0%; it is not exactly 100%.
What to inspect in the code
Bulk volume classification estimates buy and sell volume from standardized bucket price changes. The tick rule uses trade-to-trade price direction. Neither method observes the true identity or intent of a trader. Their difference here shows why changing the classification rule can change an apparent toxicity signal.
The tests also cover a special case: constant positive price changes have zero dispersion. The implementation handles that case by price-change sign, so a uniformly rising tape does not incorrectly receive a balanced 50/50 split. Flat changes receive an even split.
Limits and a useful next experiment
This is one seed and one constructed tape. It does not verify that VPIN predicts volatility in a real market. Try a different bucket size or window, keeping the trade tape fixed, to separate estimator sensitivity from changes in the underlying inputs. Such variants are experiments, not results reported here.
Download the expected bucket output or inspect the tests at the checked revision.