Open jolinmaj opened 7 months ago
Issue:
BokehDeprecationWarning: Passing lists of formats for DatetimeTickFormatter scales was deprecated in Bokeh 3.0. Configure a single string format for each scale /Users/administrator/PycharmProjects/Trading UI/venv/lib/python3.10/site-packages/backtesting/_plotting.py:250: UserWarning: DatetimeFormatter scales now only accept a single format. Using the first provided: '%m/%Y' formatter=DatetimeTickFormatter(days=['%d %b', '%a %d'],
Go to Code in plotting.py (line 250)
if is_datetime_index:
fig_ohlc.xaxis.formatter = CustomJSTickFormatter(
args=dict(axis=fig_ohlc.xaxis[0],
formatter=DatetimeTickFormatter(days=['%d %b', '%a %d'],
months=['%m/%Y', "%b'%y"]),
source=source),
code='''
Replace with:
if is_datetime_index:
fig_ohlc.xaxis.formatter = CustomJSTickFormatter(
args=dict(axis=fig_ohlc.xaxis[0],
formatter=DatetimeTickFormatter(days='%m/%d', months='%m/%Y'),
source=source),
code='''...'''
)
Expected Behavior
Chart wiht no warnings
Actual Behavior
DatetimeFormatter scales now only accept a single format. Using the first provided: '%d %b' DatetimeFormatter scales now only accept a single format. Using the first provided: '%m/%Y'
from backtesting import Strategy from backtesting.lib import crossover from backtesting import Backtest
class SmaCross(Strategy): n1 = 91 # Moving average period
Run the backtest with the new parameters
bt = Backtest(df, SmaCross, cash=10_000_000, commission=.002)
stats = bt.optimize(n1=range(50, 100, 200),
print(f"Best parameters: n1={stats._strategy.n1}")
stats = bt.run()
bt.plot()
Now plot the results
bt.plot() stats