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/

    Multi-Data example help

    General Code/Help
    1
    2
    89
    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.
    • Brandon La Porte
      Brandon La Porte last edited by

      Hi,
      I'm trying to get multiple feeds to show up on the same plot. I am using theMulti-Data Example as a reference. Here is my code below

      
      # imports above here 
      
      if __name__ == "__main__":
      
          # adjust plot settings
          style.use("bmh")
          plt.rcParams["figure.figsize"] = [10.0, 8.0]
          plt.rcParams["figure.dpi"] = 150
      
          # cerebro is the backtest runner
          cerebro = bt.Cerebro()
      
          # ------------------------------------------ #
          # --- Get, process and add data to feeds --- #
          # ------------------------------------------ #
      
          data_dir = "data/vanguardBnH/"
          files = os.listdir(data_dir)
          datas = []
      
          for filename in files:
              datapath = os.path.join(data_dir, filename)
              # Create a Data Feed
      
              datas.append(
                  bt.feeds.YahooFinanceCSVData(
                      dataname=datapath,
                      # Do not pass values before this date
                      fromdate=datetime.datetime(2017, 1, 1),
                      # Do not pass values after this date
                      todate=datetime.datetime(2019, 12, 31),
                      reverse=False,
                  )
              )
      
              for i, data in enumerate(datas):
                  if i != 0:
                      data.plotinfo.plotmaster = datas[0]
      
                  cerebro.adddata(data)
      
      
          # ------------------------------------------ #
          # --- Cerebro Backtest setup             --- #
          # ------------------------------------------ #
      
          strats = cerebro.run()
      
          cerebro.plot(volume=False)
      
      

      This results in the following plot
      Figure_0.png

      I assume I am missing something really easy but I haven't been able to figure it out.

      Brandon La Porte 1 Reply Last reply Reply Quote 0
      • Brandon La Porte
        Brandon La Porte @Brandon La Porte last edited by

        @Brandon-La-Porte It was indeed something easy, wrong indentation level.

        for i, data in enumerate(datas):
                    if i != 0:
                        data.plotinfo.plotmaster = datas[0]
        
                    cerebro.adddata(data)
        

        This was the wrong indentation and ended up being ran more the once.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }