Skip to content

Add order flow module: tick rule, Lee-Ready, bulk volume classification and VPIN - #318

Open
Mattbusel wants to merge 1 commit into
avhz:mainfrom
Mattbusel:order-flow-vpin
Open

Mattbusel wants to merge 1 commit into
avhz:mainfrom
Mattbusel:order-flow-vpin

Conversation

@Mattbusel

Copy link
Copy Markdown

This adds RustQuant_trading::order_flow, which signs trades with the tick rule or Lee-Ready (as OrderSide::BID / OrderSide::ASK), splits bar volume with bulk volume classification using Gaussian::cdf from RustQuant_math, and computes VPIN from Easley, Lopez de Prado and O'Hara (2012) over fixed-volume buckets. The expected values in the 10 unit tests are worked out by hand: alternating unit trades give exactly 0.2 in 5-unit buckets and 0 in 4-unit buckets, a 25 buy then 15 sell across 10-unit buckets gives 0.75, and a bulk-classified bar with close changes +1 and -1 gives erf(1/2) = 0.5204998778. cargo test -p RustQuant_trading passes (19 unit tests and 3 new doctests), and clippy reports nothing in the new module. It is ported from flowtox, an MIT crate I maintain, and the only new dependencies are the workspace crates RustQuant_error and RustQuant_math.

…on and VPIN

RustQuant_trading::order_flow signs trades and measures order flow
toxicity. TickRule and LeeReady classify individual trades as buyer or
seller initiated (OrderSide::BID / OrderSide::ASK). BulkVolumeClassifier
splits bar volume with Phi(dP / sigma) using the sample standard deviation
of recent close changes, as in Easley, Lopez de Prado and O'Hara (2012).
Vpin fills fixed-volume buckets, splitting trades that overflow a bucket,
and averages |V_buy - V_sell| / V over the last n buckets.

The unit tests check hand-computed values: alternating unit trades in
buckets of five give 0.2 and in buckets of four give exactly 0, and the
bulk-classified bar gives erf(1/2).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant