kernc / backtesting.py

:mag_right: :chart_with_upwards_trend: :snake: :moneybag: Backtest trading strategies in Python.
https://kernc.github.io/backtesting.py/
GNU Affero General Public License v3.0
5.59k stars 1.08k forks source link

bt.plot() does not show graph in vscode's ipynb #1043

Open ck0099 opened 1 year ago

ck0099 commented 1 year ago

Note: Just in case this is a vscode error not a backtestingPY's, I have also created an issue under vscode: https://github.com/microsoft/vscode-jupyter/issues/15407

Expected Behavior

After executing the bt.plot(), should expect the output graph to be displayed directly under the cell that executed the code in notebook.

Screen Shot 2023-08-12 at 10 22 08 PM

Actual Behavior

The graph is not plotted inside notebook. Instead it got displayed in a browser.

I even tried the following hack, but still no work:

import backtesting backtesting.set_bokeh_output(notebook=True)

Screen Shot 2023-08-12 at 10 10 52 PM

Steps to Reproduce

Just code the backtesting.py sample code inside a vscode ipynb notebook, it will display this issue.

I even downgraded to bokeh==2.4.3, but still not work

macOS 12.6.8 VScode Version: 1.81.1

My installed packages:

appnope==0.1.3 asttokens==2.2.1 attrs==23.1.0 backcall==0.2.0 Backtesting==0.3.3 bokeh==2.4.3 comm==0.1.4 contourpy==1.1.0 cycler==0.11.0 debugpy==1.6.7 decorator==5.1.1 executing==1.2.0 fastjsonschema==2.18.0 fonttools==4.42.0 ipykernel==6.25.0 ipython==8.14.0 jedi==0.19.0 Jinja2==3.1.2 jsonschema==4.19.0 jsonschema-specifications==2023.7.1 jupyter_client==8.3.0 jupyter_core==5.3.1 kiwisolver==1.4.4 MarkupSafe==2.1.3 matplotlib==3.7.2 matplotlib-inline==0.1.6 nbformat==5.9.2 nest-asyncio==1.5.7 numpy==1.25.2 packaging==23.1 pandas==1.5.2 pandas-ta==0.3.14b0 parso==0.8.3 pexpect==4.8.0 pickleshare==0.7.5 Pillow==10.0.0 platformdirs==3.10.0 plotly==5.16.0 prompt-toolkit==3.0.39 psutil==5.9.5 ptyprocess==0.7.0 pure-eval==0.2.2 Pygments==2.16.1 pyparsing==3.0.9 python-dateutil==2.8.2 pytz==2023.3 PyYAML==6.0.1 pyzmq==25.1.0 referencing==0.30.2 rpds-py==0.9.2 seaborn==0.12.2 six==1.16.0 stack-data==0.6.2 TA-Lib==0.4.27 tenacity==8.2.2 tornado==6.3.2 traitlets==5.9.0 typing_extensions==4.7.1 tzdata==2023.3 wcwidth==0.2.6 xyzservices==2023.7.0

ck0099 commented 1 year ago

I also tried this, but still not work:

bt.plot(open_browser=False)

nethinwei commented 1 year ago

Same issue.

Lxhooooo commented 1 year ago

The same problem, but it is in colab TypeError: bokeh.models.tools.Toolbar() got multiple values for keyword argument 'logo'

champon1020 commented 1 year ago

As the quick fix, you can use plot() method by installing bokeh==3.1.1.

kernc commented 1 year ago

I even tried the following hack, but still no work:

import backtesting
backtesting.set_bokeh_output(notebook=True)

Might be that VSCode doesn't permit loading HTML + JS notebook widgets. It's the same in PyCharm ... :thinking:

sternline commented 1 year ago

Seems this might be a vscode issue. As a temporary solution, open the generated .html file in file explorer and open with web browser to view the plot.

arindampradhan commented 6 months ago

Solved the issue by appending the following

import os
import bokeh
os.environ['JPY_PARENT_PID'] = '3'
bokeh.__version__

from bokeh.io import output_notebook

output_notebook()
Fayord commented 2 weeks ago

thanks arindampradhan your solutions works