You are here:  Home » 量化交易与机器学习 » backtrader » PyFolio概述 – backtrader中文教程

PyFolio Overview

Note

As(至少)2017年7月25日的pyfolio的API已经改变和create_full_tear_sheet不再有gross_lev作为命名//quantopian.github.io/pyfolio/:argument.

Consequently整合样品不从主

在HTTP页面workpyfolioQuoting

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

而且现在它的工作原理也很好用backtrader。只需要什么:

  • pyfolioobviously
  • And它的依赖(之类的东西pandas, seaborn…)

    Note

    During与版本整合0.5.1,更新最需要近期依赖关系的包,像seaborn从以前安装的0.7.0-dev0.7.1,显然是由于不存在该方法swarmplot

Usage

  1. Add的PyFolio分析器到cerebro的组合:
    cerebro.addanalyzer(bt.analyzers.PyFolio)
    
  2. 运行并检索1st策略:
    strats = cerebro.run()
    strat0 = strats[0]
    
  3. 用你给它或默认的任何名称检索分析命名将给予它:pyfolio。例如:
    pyfolio = strats.analyzers.getbyname("pyfolio")
    
  4. 使用分析器方法get_pf_items以检索4个组分以后需要pyfolio
    returns, positions, transactions, gross_lev = pyfoliozer.get_pf_items()
    

    !note

    The integration was done looking at test samples available with
    `pyfolio` and the same headers (or absence of) has been replicated
    
  5. 一起工作pyfolio(这已经是外面的backtrader生态系统)

一些使用说明不直接相关的backtrader

  • pyfolio自动绘图工作外的Jupyter Notebook,但它的工作原理best inside
  • pyfolio数据表输出似乎勉强的Jupyter
    Notebook
    之外工作。它的工作原理里面的Notebook

的结论很容易,如果有工作pyfolio是希望:里面工作Jupyter Notebook

Sample Code

The代码应该是这样的:

...
cerebro.addanalyzer(bt.analyzers.PyFolio, _name="pyfolio")
...
results = cerebro.run()
strat = results[0]
pyfoliozer = strat.analyzers.getbyname("pyfolio")
returns, positions, transactions, gross_lev = pyfoliozer.get_pf_items()
...
...
# pyfolio showtime
import pyfolio as pf
pf.create_full_tear_sheet(
    returns,
    positions=positions,
    transactions=transactions,
    gross_lev=gross_lev,
    live_start_date="2005-05-01",  # This date is sample specific
    round_trips=True)

# At this point tables and chart will show up

Reference

Look到分析仪参考了PyFolio分析仪并分析它使用internally

评论被关闭。