Skip to main content

Order flow risk measures in Python

Project description

Order Flow Risk Measures

Has been updated to support Python 3.8. Currently, the packages only has VPIN.

Installation

The default way is to open a console and execute

pip install flowrisk

One may also download from here and manually install

git clone https://github.com/hanxixuana/flowrisk
cd flowrisk
python setup.py install

VPIN

To implement VPIN, we made

1.  an EWMA estimator of volatility (RecursiveEWMAVol)
2.  a numpy.ndarray based buckets with bulk classification of volumes in the MA style (RecursiveBulkClassMABuckets)
3.  a numpy.ndarray based buckets with bulk classification of volumes in the EWMA style 
    (RecursiveBulkClassEWMABuckets)
4.  a recursive VPIN estimator (RecursiveVPIN)
5.  a recursive VPIN estimator with VPIN confidence intervals (RecursiveConfVPIN)
6.  a recursive model using an EWMA estimator of means and RecursiveEWMAVol, for modeling and log 
    innovations of VPINs and for calculating VPINs' confidence intervals (RecursiveEWMABand)
7.  a one-shoot VPIN estimator for a series of prices (BulkVPIN)
8.  a one-shoot VPIN estimator for a series of prices with VPIN confidence intervals (BulkConfVPIN)
9.  various configuration classes (RecursiveVPINConfig, RecursiveConfVPINConfig, BulkVPINConfig, 
    BulkConfVPINConfig)

For illustration, we also put the 1-min data of five small caps (CBIO, FBNC, GNC NDLS, QES) and five large caps (V, AAPL, NVDA, GS, INTC) from the US stock market. The data covers Nov 12 to Nov 21, 2018. The data can used by, for example,

import flowrisk as fr

class Config(fr.BulkConfVPINConfig):    
    N_TIME_BAR_FOR_INITIALIZATION = 50

config = Config()

example = fr.examples.USStocks(config)
symbols = example.list_symbols('small')
result = example.estimate_vpin_and_conf_interval(symbols[0])

example.draw_price_vpins_and_conf_intervals()

The piece of the code will automatically calculate VPINs and associated confidence intervals of GNC. We also put prices and volumes together with them into a nice picture, which is saved to ./pics/gnc.png by default. Note that the calculation of VPINs is fast, but making nice pictures is slow. One may also find out more in test.py.

Note that there are several differences between this implementation and the original paper:

Easley, D., L贸pez de Prado, M. M., & O'Hara, M. (2012). Flow toxicity and liquidity in a high-frequency world. 
The Review of Financial Studies, 25(5), 1457-1493.

For example,

1.  we use an EWMA estimator for the volatility of PnLs, instead of using all samples for estimating the PnL 
    volatility; and
2.  VPINs are calculated from the very beginning, instead of after a certain number of buckets have been filled.

We made the differences because the core of our package is a recursive estimator of VPIN.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flowrisk-0.3.0.tar.gz (2.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flowrisk-0.3.0-py3-none-any.whl (276.3 kB view details)

Uploaded Python 3

File details

Details for the file flowrisk-0.3.0.tar.gz.

File metadata

  • Download URL: flowrisk-0.3.0.tar.gz
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for flowrisk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a58f806a092cd96c5f22b13910d7799dc91123c65a8fe11d73bcd31be4501b3c
MD5 ea4e01d70bc2f4de6040ed84acc6c4dc
BLAKE2b-256 d0a5b6a449f5ed20ffdaf08437aa5d20c9691e55fad8ac6cbc72b3c4aa855802

See more details on using hashes here.

File details

Details for the file flowrisk-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: flowrisk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 276.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for flowrisk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1df402b3c84030318ba371c12871f6e53c0ffbe655d9f663782e430efb6cf90b
MD5 1f4a317c08353e7c85f1d967df51f0c7
BLAKE2b-256 1f00279a2e16b7ad6a8d2d9e2482704399102fa53dee1bae3d66bc2b4ffa495b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page