Newb issue with Bokeh plotting when Utilizing Pandas Data Feed
-
Newb question. Not much Python or backtesting experience
I'm having an issue with plotting in Bokeh if utilizing the Pandas data feed. Backtrader appears to take the data fine & all outputs appear identical to results if utilize the 'GeneralCSVData', but the Bokeh plotting seems to have all the datetimes in the plots legend across the top as shown:
Here's the setup. I keep thinking its something with the way I'm formatting the pandas dataframe going in, though I've looked at a few examples in this forum & am unable to ascertain the issue:
df = pd.read_csv( r'C:\Users\JT\Dropbox\John\Buildout\Backtrader\test\1hourES.csv') df.columns = map(str.lower, df.columns) df = df[['time', 'open', 'high', 'low', 'close', 'volume']] df['time'] = pd.to_datetime(df['time'], unit='s') data = bt.feeds.PandasData(dataname=df, fromdate=dt(2020, 6, 1), todate=dt(2020, 7, 7), datetime='time', open='open', high='high', low='low', close='close', volume='volume', openinterest=-1, timeframe=bt.TimeFrame.Minutes, compression=60, ) #Later in code plotting is: b = Bokeh(filename='chart.html', style='bar', plot_mode="single", scheme=Blackly() # , barup='green' ) cerebro.plot(b)
I've also tried the Tradimo plotting scheme & had the same results.
Switching out the declaration of 'data' to take the information from a CSV like so, fixes the issue, but I'd really like to understand it from a Pandas perspective to work on some more flexible ideas in the future. CSV working:
data = bt.feeds.GenericCSVData(dataname=r'C:\Users\JT\Dropbox\John\Buildout\Backtrader\test\1hourES.csv', fromdate=dt(2020, 6, 1), todate=dt(2020, 7, 7), # datetime=6, dtformat=1, datetime=0, time=-1, open=1, high=2, low=3, close=4, volume=5, openinterest=-1, timeframe=bt.TimeFrame.Minutes, compression=60 )
Any help would be appreciated. Thank You
-
To those that may come across this thread, I cannot explain why the issue is occurring, but if you pass a name to the default data when utilizing 'adddata', the legend will look normal again. Fixed
#Don't use this: cerebro.adddata(data) #Use a name with the data: cerebro.adddata(data, name='OHLCV_jt')
The name comes across in the heading / legend of the master Bokeh plot as so: