python中的订单流风险度量
flowrisk的Python项目详细描述
#订单流风险度量
目前,这些包只有vpin。
##安装 默认方法是打开控制台并执行
pip install flowrisk
也可以从此处下载并手动安装
git clone https://github.com/hanxixuana/flowrisk cd flowrisk python setup.py install
##vpin蛋白 为了实现vpin,我们制作了
- an EWMA estimator of volatility (RecursiveEWMAVol)
- a numpy.ndarray based buckets with bulk classification of volumes in the MA style (RecursiveBulkClassMABuckets)
- a numpy.ndarray based buckets with bulk classification of volumes in the EWMA style (RecursiveBulkClassEWMABuckets)
- a recursive VPIN estimator (RecursiveVPIN)
- a recursive VPIN estimator with VPIN confidence intervals (RecursiveConfVPIN)
- 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)
- a one-shoot VPIN estimator for a series of prices (BulkVPIN)
- a one-shoot VPIN estimator for a series of prices with VPIN confidence intervals (BulkConfVPIN)
- various configuration classes (RecursiveVPINConfig, RecursiveConfVPINConfig, BulkVPINConfig, BulkConfVPINConfig)
为了说明这一点,我们还将五个小型大写字母(cbio、fbnc、gnc ndls、qes)和五个大型大写字母的1分钟数据 (v,aapl,nvda,gs,intc)来自美国股市。数据涵盖2018年11月12日至11月21日。数据可以被, 例如,
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()
这段代码将自动计算vpin和gnc的相关置信区间。我们还把 价格和数量加在一起形成一张漂亮的图片,默认保存到./pics/gnc.png。请注意 vpins的计算速度很快,但是制作好的图片却很慢。也可以在test.py中找到更多信息。
请注意,此实现与原始文件有几个不同之处:
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.
例如,
- we use an EWMA estimator for the volatility of PnLs, instead of using all samples for estimating the PnL volatility; and
- VPINs are calculated from the very beginning, instead of after a certain number of buckets have been filled.
我们之所以有所不同,是因为我们包的核心是vpin的递归估计。