backtesting.py
backtesting.py copied to clipboard
Plotting does not work with Bokeh v3.0
Expected Behavior
I installed the tool and all required libraries on Ubuntu 22.04, Python 3.11.0 and ta-lib (compiled from latest source code 0.4.0). The backtest from the example code on home page was run. The test itself ran without
problems but the plot html does not work. It should show the graph.
Actual Behavior
Please see the attached. The html layout is not working. Strangely, no JS error from browser console.
Steps to Reproduce
- Install backtesting.py
- Run the example code on the project home page
- Open the plot in IE Edge
Additional info

- Backtesting version: 0.3.3
Downgrading bokeh==3.0.1 to bokeh==2.4.3 fixed this issue for me
Downgrading bokeh==3.0.1 to bokeh==2.4.3 fixed this issue for me
Thank you. I also fixed it by using Python 3.7 instead
This is Bokeh bugs: https://github.com/bokeh/bokeh/issues/12614 ~~https://github.com/bokeh/bokeh/issues/12627~~
Please upvote, fix.
Same issue here using the following for now: python=3.8.15 bokeh=2.4.3
doesn't work for python 3.9, including the workaround of switching bokeh into version 2.4.3
anyone knows?
Doesnot work for python 3.9
Downgrading bokeh==3.0.1 to bokeh==2.4.3 fixed this issue for me
Does work for python 3.10 on macOS
@bashu while issue gets resolved upstream, running the line below got it working using bokeh version 2.4.2 in MacOS with python 3.9.6 and Backtesting 0.3.3
pip install --force-reinstall bokeh==2.4.2
If your attempt still can't work maybe you can try the code below, it does work for me.
don't type like this: import backtesting backtesting.set_bokeh_output(notebook=False)
try this: from backtesting import set_bokeh_output set_bokeh_output(notebook=False)
my version info below: Spyder 5.3.3 Python 3.8.12 bokeh 2.4.3 backtesting 0.3.3
I realise that the problem was probably caused by the installed pandas version 2.1. Apparently, the parameter method has been deprecated and removed after pandas 2.0.
By installing pandas 1.5.2, it is able to plot.
pip install pandas==1.5.2
Hope this helps for the time being.
Not sure how to fix the code, any ideas?
File ~/.local/lib/python3.10/site-packages/backtesting/_plotting.py:148, in _maybe_resample_data.<locals>._group_trades.<locals>.f(s, new_index, bars)
147 mean_time = int(bars.loc[s.index].view(int).mean())
--> 148 new_bar_idx = new_index.get_loc(mean_time, method='nearest')
149 return new_bar_idx
TypeError: Index.get_loc() got an unexpected keyword argument 'method'
bt.plot does not work for me. I have tried all the suggested above solutions but no one worked. Always coped with error: "Bound method Backtest.plot of <backtesting.backtesting.Backtest object at 0x7dc0f4917520"