Bulk Volume Classification
Install and import
npm install fintech-algorithmsimport { bulkVolumeClassification } from "fintech-algorithms/market-microstructure/trade-classification/bulk-volume-classification";Signature
bulkVolumeClassification(data, config)Assigns a *fraction* of each volume bar to buyers rather than signing individual trades. Designed for aggregated data where trade-level signing is impossible, and the input to VPIN.
Parameters
| Name | Type | Notes |
|---|---|---|
data | ClassificationInput | Trades with prices, and where the rule needs them, the prevailing quotes. |
config | ClassificationConfig | Tolerances and tie-breaking rules. Trades exactly at a quote or unchanged in price are the cases where classifiers differ, so the tie rule is part of the contract. |
Returns
{ classifications, summary, diagnostics }
Per-trade sign with the rule that produced it, plus counts of the unclassifiable cases. Bulk volume classification disagrees with its siblings on exactly those, and hiding them would hide the disagreement.
Errors
- When required quote data is absent for a rule that needs it — reported per trade rather than thrown
Complexity: time O(n),
space O(n).
Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
{
"starting_price": 100,
"bars": [
{
"id": "B001",
"sequence": 1,
"event_time_ms": 1000,
"close": 100.05,
"volume": 1000,
"status": "valid"
},
{
"id": "B002",
"sequence": 2,
"event_time_ms": 61000,
"close": 100.05,
"volume": 1125,
"status": "valid"
},
{
"id": "B003",
"sequence": 3,
"event_time_ms": 121000,
"close": 100.025,
"volume": 1250,
"status": "valid"
}
]
}{
"sigma": 0.05,
"degrees_of_freedom": 1
}Call
bulkVolumeClassification(data, config)Returns
object with 17 fields: state, method, trace, total_valid, classified_count, unknown_count, buy_count, sell_count, …
{
"state": "ok",
"method": "bulk-volume-classification",
"trace": [
{
"id": "B001",
"sequence": 1,
"event_time_ms": 1000,
"price": 100.05,
"volume": 1000,
"sign": 1,
"side": "buy-leaning",
"reason": "student-t-volume-split",
"price_change": 0.05,
"z_score": 1,
"buy_fraction": 0.75,
"buy_volume": 750,
"sell_volume": 250,
"cumulative_signed_volume": 500
},
{
"id": "B002",
"sequence": 2,
"event_time_ms": 61000,
"price": 100.05,
"volume": 1125,
"sign": 0,
"side": "balanced",
"reason": "student-t-volume-split",
"price_change": 0,
"z_score": 0,
"buy_fraction": 0.5,
"buy_volume": 562.5,
"sell_volume": 562.5,
"cumulative_signed_volume": 500
},
{
"id": "B003",
"sequence": 3,
"event_time_ms": 121000,
"price": 100.025,
"volume": 1250,
"sign": -1,
"side": "sell-leaning",
"reason": "student-t-volume-split",
"price_change": -0.025,
"z_score": -0.5,
"buy_fraction": 0.3524163823,
"buy_volume": 440.520477937,
"sell_volume": 809.479522063,
"cumulative_signed_volume": 131.040955874
}
],
"total_valid": 60,
"classified_count": 60,
"unknown_count": 0,
"buy_count": 24,
"sell_count": 24,
"buy_volume": 47435.5504890151,
"sell_volume": 41439.4495109849,
"unknown_volume": 0,
"signed_volume": 5996.1009780303,
"total_volume": 88875,
"coverage": 1
}Showing 14 of 17 fields.
Other exports
This module also exports
tickTest, quoteTest, leeReady, studentTCdf, runTopic. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- Discerning Information from Trade Data — David Easley, Marcos Lopez de Prado, and Maureen O'Hara
- Nasdaq TotalView-ITCH 5.0 Specification — Nasdaq
- Daily TAQ Client Specification — NYSE / ICE Data Services