pyfolio

repository·master·Indexed 27 days ago

https://github.com/quantopian/pyfolio

A Python library for the performance and risk analysis of financial portfolios. It integrates with the Zipline backtesting library to generate 'tear sheets'—comprehensive visual reports of trading algorithm performance. Features include risk exposure analysis, performance attribution, intraday strategy analysis, and Bayesian tear sheets with Fama-French factors.

Tokens
776
Snippets
4
Records
12
Agent score
42%

What's inside pyfolio

  1. Set up pyfolio for development

    master

    To develop on pyfolio, it is recommended to use a virtual environment to avoid dependency conflicts. Follow these steps:

    1. Create a virtual environment using mkvirtualenv.
    2. Clone the repository.
    3. Install the package in development mode using python setup.py develop.
    mkvirtualenv pyfolio
    # After cloning the repo:
    python setup.py develop
  2. Analyze performance without a benchmark

    master
    As of v0.9.0, pyfolio is independent of benchmarks. This allows for the analysis of international equities and alternative data sets. If you pass a benchmark (e.g., SPY), all benchmark-related analyses will be performed. If no benchmark is passed, these analyses will be skipped.
  3. Run pyfolio examples in Jupyter Notebook

    master

    The best way to explore pyfolio's capabilities is by running the provided examples in a Jupyter notebook:

    1. Start a Jupyter notebook server by running jupyter notebook in your terminal.
    2. In the browser, navigate to the pyfolio/examples directory.
    3. Open a notebook and execute cells using Shift+Enter.
    jupyter notebook
  4. Configure Matplotlib on OSX

    master

    If you are using OSX with a non-framework build of Python, you may need to manually set the Matplotlib backend to TkAgg to ensure plots render correctly.

    echo "backend: TkAgg" > ~/.matplotlib/matplotlibrc
  5. Analyze intraday strategies

    master

    As of v0.7.0, pyfolio has basic capability for analyzing intraday strategies. If a strategy has a high transaction volume relative to end-of-day positions, pyfolio attempts to reconstruct intraday positions and plot peak market exposure. You can control this behavior using the estimate_intraday parameter in tear sheet functions:

    • estimate_intraday=True: Automatically attempt to reconstruct intraday positions.
    • estimate_intraday=False: Disable intraday reconstruction.
  6. Use the Risk tear sheet for factor exposure analysis

    master
    Introduced in v0.8.0, the Risk tear sheet allows you to analyze risk exposures to common factors (such as mean reversion and momentum), sectors (e.g., Morningstar sectors), market cap, and illiquid stocks.
  7. Perform performance attribution analysis

    master
    Introduced in v0.8.0, performance attribution analysis includes new tables to determine returns attributable to common factors and summary statistics like multi-factor alpha and multi-factor Sharpe ratio.