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

Is it possible to label each plot when plotting multi assets using a PandasData feed?

  • I'm utilizing NorgateData to read in local EOD data into a Pandas Dataframe, and then loading that data into a cerebro and plotting it for multiple assets, but unfortunately I'm not finding a way to have each of the plots labeled with the individual tickers. This is a bit of a pain when I'm using a long list of stocks for my universe, and trying to analyze trades.

    Is there a way to assign a name to each plot when using a Pandas data feed?

    Thanks in advance!

  • I found the answer in another post. When I'm looping through my data, I rename the dataframe columns to fit the BT convention, then I convert that into a data feed and apply the name.

    I'll share my Norgate Data Code here for future reference.

    # Obtain a Pandas dataframe for a given security from Norgate Data
    priceadjust = norgatedata.StockPriceAdjustmentType.TOTALRETURN 
    padding_setting = norgatedata.PaddingType.NONE   
    start_date = '2019-05-01'
    #end_date = '2011-12-31'
    timeseriesformat = 'pandas-dataframe'
    universe = ['AAPL','TSLA']#,'GE','AMD','SPY']
    for ticker in universe:
        pricedata_dataframe = norgatedata.price_timeseries(
            stock_price_adjustment_setting = priceadjust,
            padding_setting = padding_setting,
            start_date = start_date,
            #end_date = end_date,
        # Rename columns to suit Backtrader
            columns={ 'Open':'open',  'High':'high', 'Low':'low', 'Close':'close', 'Volume':'volume', 'Open Interest':'open interest'},
        data = bt.feeds.PandasData(dataname=pricedata_dataframe)
        data._name = ticker

    Anyways, thanks for creating and sharing such an amazing project.

Log in to reply