Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    fix for get_pf_items?

    General Discussion
    2
    3
    87
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      crunchypickle last edited by

      The code was giving positions in the form of

      Datetime, single_ticker, cash
      

      When pyfolio expects, as per documentation, multiple ticker columns

          positions : pd.DataFrame, optional
              Daily net position values.
               - Time series of dollar amount invested in each position and cash.
               - Days where stocks are not held can be represented by 0 or NaN.
               - Non-working capital is labelled 'cash'
               - Example:
                  index         'AAPL'         'MSFT'          cash
                  2004-01-09    13939.3800     -14012.9930     711.5585
                  2004-01-12    14492.6300     -14624.8700     27.1821
                  2004-01-13    -13853.2800    13653.6400      -43.6375
      

      under get_pf_items it has

      ps = [[k] + v[-2:] for k, v in iteritems(pss)]
      

      I think this was trying to generate single positions, and somehow recombine them later?

      But variable pss is already a ordered dict in the form of

      {'Datetime': ['ABIO', 'ACHV', 'ACY', 'AEMD', 'AEYE', 'cash']}
      {Datetime : [0.0, 0.0, 0.0, 0.0, 0.0, 100000.0]}
      

      So simply making a list of list is enough to pass it into pandas

      ps = [[k] + v for k, v in iteritems(pss)]
      

      This made my Pyfolio tear sheet graphs work properly

      Li Mike 1 Reply Last reply Reply Quote 0
      • Li Mike
        Li Mike @crunchypickle last edited by

        @crunchypickle do you mean you can use pyfolio now?

        1 Reply Last reply Reply Quote 0
        • C
          crunchypickle last edited by

          Not sure how you use it. but i just use tear sheet and its working fine.

          I think i might have fixed some other bugs, but there are github issues that have solutions.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors