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.39k stars 1.05k forks source link

Bokeh not plotting the official website snippet #926

Closed jsulopzs closed 1 year ago

jsulopzs commented 1 year ago

Expected Behavior

Actual Behavior

You may watch the following Loom video to understand the possible error:

https://www.loom.com/share/a078b84b92ba46feb1a9abf2d8fc8b93

Steps to Reproduce

  1. Install backtesting library pip install backtesting
  2. Copy-paste a snippet of code from the official website.
  3. Execute the code.

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

from backtesting.test import SMA, GOOG

class SmaCross(Strategy):
    n1 = 10
    n2 = 20

    def init(self):
        close = self.data.Close
        self.sma1 = self.I(SMA, close, self.n1)
        self.sma2 = self.I(SMA, close, self.n2)

    def next(self):
        if crossover(self.sma1, self.sma2):
            self.buy()
        elif crossover(self.sma2, self.sma1):
            self.sell()

bt = Backtest(GOOG, SmaCross,
              cash=10000, commission=.002,
              exclusive_orders=True)

output = bt.run()
bt.plot()

Additional info

jsulopzs commented 1 year ago

Already solved in #803