For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Plot 2 stock prices in same axis in cerebro.plot() ???



  • Hi guys, it is possible to put 2 stock prices together in same axis using cerebro.plot() ?
    I want to use it to do some correlation analysis between stocks indexes & single stock.



  • If your first datas is data0, then when building your second and other datas you need to insert:

    data1.plotinfo.plotmaster = data0
    

    So for example, if loading three datas from a dataframe, it would look like this:

    # Add Nasdaq qqq data line.
        data0 = bt.feeds.PandasData(
            dataname=pd.read_hdf("store.h5", "qqq").loc[date_start:date_end, :],
            name="qqq",
            plot=True,
        )
        cerebro.adddata(data0)
    
        # Add S&P500 spy data line.
        data1 = bt.feeds.PandasData(
            dataname=pd.read_hdf("store.h5", "spy").loc[date_start:date_end, :],
            name="spy",
            plot=True,
        )
        data1.plotinfo.plotmaster = data0
        cerebro.adddata(data1)
    
        # Add S&P short SH data line.
        data2 = bt.feeds.PandasData(
            dataname=(pd.read_hdf("store.h5", "sh").loc[date_start:date_end, :]),
            name="sh",
            plot=True,
        )
        data2.plotinfo.plotmaster = data0
        cerebro.adddata(data2)
    

Log in to reply
 

});