pyfolio is a Python library for performance and risk analysis of financial portfolios developed by Quantopian Inc. It works well with the Zipline open source backtesting library.
At the core of pyfolio is a so-called tear sheet that consists of various individual plots that provide a comprehensive image of the performance of a trading algorithm. Here's an example of a simple tear sheet analyzing a strategy:
Also see slides of a talk about pyfolio.
To install pyfolio, run:
pip install pyfolio
For development, you may want to use a virtual environment to avoid dependency conflicts between pyfolio and other Python projects you have. To get set up with a virtual env, run:
mkvirtualenv pyfolio
Next, clone this git repository and run python setup.py develop
and edit the library files directly.
Generating a Bayesian tearsheet requires PyMC3 and Theano. You can install these packages with the following commands:
pip install theano
pip install pymc3
If you are on OSX and using a non-framework build of Python, you may need to set your backend:
echo "backend: TkAgg" > ~/.matplotlib/matplotlibrc
A good way to get started is to run the pyfolio examples in a Jupyter notebook. To do this, you first want to start a Jupyter notebook server:
jupyter notebook
From the notebook list page, navigate to the pyfolio examples directory and open a notebook. Execute the code in a notebook cell by clicking on it and hitting Shift+Enter.
If you find a bug, feel free to open an issue in this repository.
You can also join our mailing list or our Gitter channel.
Please open an issue for support.
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
and pyfolio
development teams 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
(and therefore pyfolio
, which is a downstream
dependency) 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:
pyfolio.utils.default_returns_func
pyfolio.utils.get_fama_french
pyfolio.utils.get_returns_cached
pyfolio.utils.get_symbol_returns_from_yahoo
pyfolio.utils.get_treasury_yield
pyfolio.utils.cache_dir
pyfolio.utils.ensure_directory
pyfolio.utils.data_path
pyfolio.utils._1_bday_ago
pyfolio.utils.load_portfolio_risk_factors
Users should expect regular failures from the following functions, pending patches to the Yahoo or Google Finance API:
pyfolio.utils.default_returns_func
pyfolio.utils.get_symbol_returns_from_yahoo
If you'd like to contribute, a great place to look is the issues marked with help-wanted.
For a list of core developers and outside collaborators, see the GitHub contributors list.