backtesting.py icon indicating copy to clipboard operation
backtesting.py copied to clipboard

Plotting does not work with Bokeh v3.0

Open aicheung opened this issue 3 years ago • 12 comments

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

  1. Install backtesting.py
  2. Run the example code on the project home page
  3. Open the plot in IE Edge

Additional info

Screenshot 2022-11-08 120227 Screenshot 2022-11-08 120313

  • Backtesting version: 0.3.3

aicheung avatar Nov 08 '22 12:11 aicheung

Downgrading bokeh==3.0.1 to bokeh==2.4.3 fixed this issue for me

jackjiang871 avatar Nov 09 '22 07:11 jackjiang871

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

aicheung avatar Nov 09 '22 14:11 aicheung

This is Bokeh bugs: https://github.com/bokeh/bokeh/issues/12614 ~~https://github.com/bokeh/bokeh/issues/12627~~

Please upvote, fix.

kernc avatar Nov 25 '22 04:11 kernc

Same issue here using the following for now: python=3.8.15 bokeh=2.4.3

micascheid avatar Dec 12 '22 18:12 micascheid

doesn't work for python 3.9, including the workaround of switching bokeh into version 2.4.3

anyone knows?

kiann00 avatar Jan 01 '23 07:01 kiann00

Doesnot work for python 3.9

dshetyo avatar Jan 16 '23 02:01 dshetyo

Downgrading bokeh==3.0.1 to bokeh==2.4.3 fixed this issue for me

Does work for python 3.10 on macOS

bashu avatar Jan 22 '23 08:01 bashu

@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

rogerc avatar Jan 22 '23 17:01 rogerc

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

dwellingnerd avatar Feb 11 '23 15:02 dwellingnerd

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.

AaroncoolPx avatar Oct 03 '23 15:10 AaroncoolPx

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'

AaroncoolPx avatar Oct 03 '23 15:10 AaroncoolPx

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"

tuanphongpham avatar Nov 01 '23 00:11 tuanphongpham