美文网首页
9.2 PyFolio Overvies

9.2 PyFolio Overvies

作者: wanggs66 | 来源:发表于2020-04-28 15:17 被阅读0次

    PyFolio 和 Backtrader 能很好的兼容

    Usage

    1. Add the PyFolio analyzer to the cerebro mix:
      cerebro.addanalyzer(bt.analyzers.PyFolio)

    2. Run and retrieve the 1st strategy:
      strats = cerebro.run()
      strat0 = strats[0]

    3. Retrieve the analyzer using whatever name you gave to it or the default name it will be given to it: pyfolio. For example:
      pyfolio = strats.analyzers.getbyname('pyfolio')

    4. Use the analyzer method get_pf_items to retrieve the 4 components later needed for pyfolio:
      returns, positions, transactions, gross_lev = pyfoliozer.get_pf_items()

    5. Work with pyfolio (this is already outside of the backtrader ecosystem)

    [Notes] if working with pyfolio is wished: work inside a Jupyter Notebook

    Example:

    ...
    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)
    

    通过以上方法可以利用pyfolio中的工具画出更多可视化的图片,帮助分析

    # At this point tables and chart will show up
    

    相关文章

      网友评论

          本文标题:9.2 PyFolio Overvies

          本文链接:https://www.haomeiwen.com/subject/dhnvwhtx.html