Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backtesting doesnt plot graph #132

Closed
hussanirizvi2 opened this issue Aug 26, 2020 · 5 comments
Closed

backtesting doesnt plot graph #132

hussanirizvi2 opened this issue Aug 26, 2020 · 5 comments
Labels
invalid This is not a (valid) bug report

Comments

@hussanirizvi2
Copy link

hussanirizvi2 commented Aug 26, 2020

Expected Behavior

graph to be plot

Actual Behavior

UserWarning: Jupyter Notebook detected. Setting Bokeh output to notebook. This may not work in Jupyter clients without JavaScript support (e.g. PyCharm, Spyder IDE). Reset with backtesting.set_bokeh_output(notebook=False).

Steps to Reproduce

while running the code in spyder:

from backtesting import Backtest, Strategy
from backtesting.lib import crossover

from backtesting.test import SMA, GOOG


class SmaCross(Strategy):
    def init(self):
        price = self.data.Close
        self.ma1 = self.I(SMA, price, 10)
        self.ma2 = self.I(SMA, price, 20)

    def next(self):
        if crossover(self.ma1, self.ma2):
            self.buy()
        elif crossover(self.ma2, self.ma1):
            self.sell()


bt = Backtest(GOOG, SmaCross, commission=.002,
              exclusive_orders=True)
stats = bt.run()
print(stats)
bt.plot()

Additional info

  • Backtesting version: 0.2.2
@kernc
Copy link
Owner

kernc commented Aug 26, 2020

The UserWarning spells a hint: Jupyter/IPython notebook was detected. This would not work in Jupyter clients without JavaScript support (e.g. PyCharm, Spyder IDE). Spyder is presumably such a client. Reset with backtesting.set_bokeh_output(notebook=False). This means using:

import backtesting
backtesting.set_bokeh_output(notebook=False)

in your code should help.

@kernc kernc closed this as completed Aug 26, 2020
@kernc kernc added the invalid This is not a (valid) bug report label Aug 26, 2020
@hussanirizvi2
Copy link
Author

thats it! thanks a lot!

@hosseinab
Copy link

@kernc hi
this code not work

@kernc
Copy link
Owner

kernc commented Dec 29, 2022

Please see #803.

@dwellingnerd
Copy link

dwellingnerd commented Feb 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This is not a (valid) bug report
Projects
None yet
Development

No branches or pull requests

4 participants