Common financial risk metrics.
Table of Contents
pip install empyrical
import numpy as np from empyrical import max_drawdown, alpha_beta returns = np.array([.01, .02, .03, -.4, -.06, -.02]) benchmark_returns = np.array([.02, .02, .03, -.35, -.05, -.01]) # calculate the max drawdown max_drawdown(returns) # calculate alpha and beta alpha, beta = alpha_beta(returns, benchmark_returns)
import numpy as np from empyrical import roll_max_drawdown returns = np.array([.01, .02, .03, -.4, -.06, -.02]) # calculate the rolling max drawdown roll_max_drawdown(returns, window=3)
import pandas as pd from empyrical import roll_up_capture, capture returns = pd.Series([.01, .02, .03, -.4, -.06, -.02]) # calculate a capture ratio capture(returns) # calculate capture for up markets on a rolling 60 day basis roll_up_capture(returns, window=60)
Please open an issue for support.
Deprecated: Data Reading via
As of early 2018, Yahoo Finance has suffered major API breaks with no stable
replacement, and the Google Finance API has not been stable since late 2017
In recent months it has become a greater and greater strain on the
development team to maintain support for fetching data through
pandas-datareader and other third-party libraries, as these APIs are known to
As a result, all
empyrical support for data reading functionality has been
deprecated and will be removed in a future version.
Users should beware that the following functions are now deprecated:
Users should expect regular failures from the following functions, pending patches to the Yahoo or Google Finance API:
- install requirements
python -m unittest