You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importnumpyasnpfromempyricalimportmax_drawdown, alpha_betareturns=np.array([.01, .02, .03, -.4, -.06, -.02])
benchmark_returns=np.array([.02, .02, .03, -.35, -.05, -.01])
# calculate the max drawdownmax_drawdown(returns)
# calculate alpha and betaalpha, beta=alpha_beta(returns, benchmark_returns)
Rolling Measures
importnumpyasnpfromempyricalimportroll_max_drawdownreturns=np.array([.01, .02, .03, -.4, -.06, -.02])
# calculate the rolling max drawdownroll_max_drawdown(returns, window=3)
Pandas Support
importpandasaspdfromempyricalimportroll_up_capture, capturereturns=pd.Series([.01, .02, .03, -.4, -.06, -.02])
# calculate a capture ratiocapture(returns)
# calculate capture for up markets on a rolling 60 day basisroll_up_capture(returns, window=60)
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
(source).
In recent months it has become a greater and greater strain on the empyrical
development team to maintain support for fetching data through
pandas-datareader and other third-party libraries, as these APIs are known to
be unstable.
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:
empyrical.utils.cache_dir
empyrical.utils.data_path
empyrical.utils.ensure_directory
empyrical.utils.get_fama_french
empyrical.utils.load_portfolio_risk_factors
empyrical.utils.default_returns_func
empyrical.utils.get_symbol_returns_from_yahoo
Users should expect regular failures from the following functions, pending
patches to the Yahoo or Google Finance API: