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/

    PyFolio performance issues on Pandas Data Frame

    Indicators/Strategies/Analyzers
    2
    3
    845
    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.
    • Y
      Yousuf last edited by

      0_1531641830697_Screen Shot 2018-07-15 at 4.03.15 PM.png

      PyFolio is returning a single value for each day when generating data frame for returns and positions. Meanwhile, transaction data frame shows intra-day execution.

      When the data is ingested from Generic CSV feed, PyFolio is able to iterate through each data observation and return positions and returns value

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        You may want to let us know (in code terms) what you have done and what your expectations are. Your message isn't clear at all.

        In any case one can tray to read between the lines that your problems may have to do with intraday data and pyfolio expects daily returns (at least with the versions that worked, because the API kept changing and there could of course have been an update)

        1 Reply Last reply Reply Quote 0
        • Y
          Yousuf last edited by Yousuf

          Apologies for not articulating the problem well enough in the first post. However, you have correctly inferred that I am facing issues with not being able to see intraday positions and returns from PyFolio analyzer.

          My run strat function looks like this:

          def runstrat1():
          
          args = parse_args()
          
          # Create a cerebro entity
          cerebro = bt.Cerebro(stdstats=True)
          
          # Add a strategy
          cerebro.addstrategy(strategy1.TestStrategy)
          
          # Get a pandas dataframe
          datapath = ('./dataset/data2.csv')
          dataframe = pd.read_csv(datapath,parse_dates=True,index_col=0)
          
          # Pass it to the backtrader datafeed and add it to the cerebro
          data = PandasDataExpanded(dataname=dataframe)
          
          cerebro.adddata(data)
          
          # Add PyFolio Analyzer
          cerebro.addanalyzer(bt.analyzers.PyFolio, _name='pyfolio')
          
          # Run over everything
          strats = cerebro.run()
          
          returns, positions, transactions, gross_lev = pyfoliozer.get_pf_items()
          
              for each in strat0.analyzers:
                  each.print()
          
              print(positions['cash'])
          
              # Plot the result
              if not args.noplot:
                  cerebro.plot(style='bar')
          
              return positions
          

          My class for pandas data feed look like this:

          class PandasDataExpanded(btfeeds.PandasData):
          
          lines = ('barCount',)
          params = (('barCount', -1),)
          
          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors