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



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


Log in to reply
 

});