Giter VIP home page Giter VIP logo

flowrisk's Introduction

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 order_flow_risk_analysis_of_ten_us_stocks.ipynb and 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.

flowrisk's People

Contributors

hanxixuana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flowrisk's Issues

online example

Hello,

In order_flow_risk_analysis_of_ten_us_stocks.ipynb notebook, you mention that BulkVPIN is suitable for online VPIN estimation.

While I'm able to generate VPINs from a dataframe and use them with an sklearn compatible model, once I try to pass new data for online generation of VPIN feature to the estimator, it does not seem to be able to handle it.:

lib/python3.8/site-packages/pandas/core/indexes/range.py in __getitem__(self, key)
    695                 return self._range[new_key]
    696             except IndexError:
--> 697                 raise IndexError(
    698                     f"index {key} is out of bounds for axis 0 with size {len(self)}"
    699                 )

IndexError: index 50 is out of bounds for axis 0 with size 50

I pass usually just a couple of rows when doing inference.

Can you provide an online example? I guess I missed something.

Also, having a scikit-learn API like interface (fit, predict, predict_proba) of the estimator would be great.

Thanks and keep the good work!

File Not Found Error: [Errno 2]

试着运行 给定的example ,报错

File Not Found Error: [Errno 2] File C:\ProgramData\Anaconda3\lib\site-packages\flowrisk-0.2.3-py3.7.egg\flowrisk\examples\data\CBIO_2018_11_22.csv does not exist

Use VPIN in my chosen stock measurement

Hello. I want to use this VPIN model to measure my stocks through python, but when I use, I can only use the data from original stock data(such as 'gd'). How can i substitute the data from the explanation to my own? thx

import failed

Traceback (most recent call last):
File "E:/PycharmProjects/api爬虫/vpin-master2/vpin-bvc.py", line 1, in
import flowrisk as fr
File "D:\Program Files (x86)\python38\lib\site-packages\flowrisk_init_.py", line 11, in
import measure
File "D:\Program Files (x86)\python38\lib\site-packages\measure_init_.py", line 5, in
from .stats import (
File "D:\Program Files (x86)\python38\lib\site-packages\measure\stats_init_.py", line 8, in
from .counter import (
File "D:\Program Files (x86)\python38\lib\site-packages\measure\stats\counter.py", line 5, in
from .stat import (
File "D:\Program Files (x86)\python38\lib\site-packages\measure\stats\stat.py", line 9, in
from measure.client.base import BaseClient
File "D:\Program Files (x86)\python38\lib\site-packages\measure\client_init_.py", line 11, in
for name, client in globals().items():
RuntimeError: dictionary changed size during iteration

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.