Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TypeError and Warnings with Bokeh 2.3.3 in Backtesting.py Plotting #1071

Unanswered
djodjobadi asked this question in Q&A
Discussion options

Hello,

I am encountering an issue while using backtesting.py for my trading strategy backtesting, specifically when attempting to plot the results of an optimization. I am receiving a TypeError along with several warnings related to Bokeh's DatetimeTickFormatter and toolbar properties. Below are the details of the issue:
Environment:

Python 3.9
Backtesting.py version: 0.3.3
Bokeh version: 2.3.3

Code Snippet:

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

class System(Strategy):
d_rsi = 30 # Daily RSI lookback periods
w_rsi = 30 # Weekly
level = 70

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

class System(Strategy):
d_rsi = 30 # Daily RSI lookback periods
w_rsi = 30 # Weekly
level = 70

def init(self):
 # Compute moving averages the strategy demands
 self.ma10 = self.I(SMA, self.data.Close, 10)
 self.ma20 = self.I(SMA, self.data.Close, 20)
 self.ma50 = self.I(SMA, self.data.Close, 50)
 self.ma100 = self.I(SMA, self.data.Close, 100)
 
 # Compute daily RSI(30)
 self.daily_rsi = self.I(RSI, self.data.Close, self.d_rsi)
 
 # To construct weekly RSI, we can use `resample_apply()`
 # helper function from the library
 self.weekly_rsi = resample_apply(
 'W-FRI', RSI, self.data.Close, self.w_rsi)
 
def next(self):
 price = self.data.Close[-1]
 
 # If we don't already have a position, and
 # if all conditions are satisfied, enter long.
 if (not self.position and
 self.daily_rsi[-1] > self.level and
 self.weekly_rsi[-1] > self.level and
 self.weekly_rsi[-1] > self.daily_rsi[-1] and
 self.ma10[-1] > self.ma20[-1] > self.ma50[-1] > self.ma100[-1] and
 price > self.ma10[-1]):
 
 # Buy at market price on next open, but do
 # set 8% fixed stop loss.
 self.buy(sl=.92 * price)
 
 # If the price closes 2% or more below 10-day MA
 # close the position, if any.
 elif price < .98 * self.ma10[-1]:
 self.position.close()

from backtesting.test import GOOG

backtest = Backtest(GOOG, System, commission=.002)
backtest.run()

backtest.optimize(d_rsi=range(10, 35, 5),
w_rsi=range(10, 35, 5),
level=range(30, 80, 10))

backtest.plot()

Error Message:

BokehDeprecationWarning: Passing lists of formats for DatetimeTickFormatter scales was deprecated in Bokeh 3.0. Configure a single string format for each scale ... UserWarning: DatetimeFormatter scales now only accept a single format. Using the first provided: '%d %b' ... UserWarning: found multiple competing values for 'toolbar.active_drag' property; using the latest value ... TypeError: bokeh.models.tools.Toolbar() got multiple values for keyword argument 'logo'
When I attempt to plot the results of a backtest optimization using the above code snippet, I encounter the aforementioned warnings and error. The warnings seem to suggest that there are deprecated usages of DatetimeTickFormatter and conflicting toolbar property values in the underlying _plotting.py of backtesting.py. The TypeError appears to be related to the 'logo' keyword argument in Bokeh's Toolbar model.

I have tried using different versions of Bokeh and backtesting.py to see if the issue persists across versions.
I have searched through existing issues in this repository and relevant forums but have not found a solution that addresses this problem.

I would greatly appreciate any guidance on how to resolve this issue, and I am happy to provide any additional information if needed. Thank you in advance for your time and assistance!

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /