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/

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

    General Discussion
    2
    2
    153
    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.
    • boshng95
      boshng95 last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • run-out
        run-out last edited by

        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)
        

        RunBacktest.com

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