gpt4 book ai didi

backtesting.py ploting function not working(BackTesting.py绘图函数不起作用)

转载 作者:bug小助手 更新时间:2023-10-25 14:36:02 38 4
gpt4 key购买 nike



I'm trying to learn backtesting.py, when I run the following sample code, it pops up these errors, anyone could help? I tried to uninstall the Bokeh package and reinstall an older version, but it doen't work.

我正在尝试学习BackTesting.py,当我运行下面的示例代码时,它弹出这些错误,有人能帮助我吗?我试图卸载Bokeh包并重新安装旧版本,但不起作用。


BokehDeprecationWarning: Passing lists of formats for DatetimeTickFormatter scales was deprecated in Bokeh 3.0. Configure a single string format for each scale
C:\Users\paul_\AppData\Local\Programs\Python\Python310\lib\site-packages\bokeh\models\formatters.py:399: UserWarning: DatetimeFormatter scales now only accept a single format. Using the first prodvided: '%d %b'
warnings.warn(f"DatetimeFormatter scales now only accept a single format. Using the first prodvided: {fmt[0]!r} ")
BokehDeprecationWarning: Passing lists of formats for DatetimeTickFormatter scales was deprecated in Bokeh 3.0. Configure a single string format for each scale
C:\Users\paul_\AppData\Local\Programs\Python\Python310\lib\site-packages\bokeh\models\formatters.py:399: UserWarning: DatetimeFormatter scales now only accept a single format. Using the first prodvided: '%m/%Y'
warnings.warn(f"DatetimeFormatter scales now only accept a single format. Using the first prodvided: {fmt[0]!r} ")
GridPlot(id='p11925', ...)

import bokeh
import datetime
import pandas_ta as ta
import pandas as pd

from backtesting import Backtest
from backtesting import Strategy
from backtesting.lib import crossover
from backtesting.test import GOOG

class RsiOscillator(Strategy):

upper_bound = 70
lower_bound = 30
rsi_window = 14

# Do as much initial computation as possible
def init(self):
self.rsi = self.I(ta.rsi, pd.Series(self.data.Close), self.rsi_window)

# Step through bars one by one
# Note that multiple buys are a thing here
def next(self):
if crossover(self.rsi, self.upper_bound):
self.position.close()
elif crossover(self.lower_bound, self.rsi):
self.buy()

bt = Backtest(GOOG, RsiOscillator, cash=10_000, commission=.002)
stats = bt.run()
bt.plot()


更多回答
优秀答案推荐

An issue was opened for this in the GitHub repo:
https://github.com/kernc/backtesting.py/issues/803

GitHub回购中为此打开了一个问题:https://github.com/kernc/backtesting.py/issues/803


A comment in the issue suggests to downgrade bokeh to 2.4.3:

该问题中的一条评论建议将Bokeh的评级下调至2.4.3:


python3 -m pip install bokeh==2.4.3

This worked for me.

这对我很管用。



I had a similar issue, using Spyder IDE.

我在使用Spyder IDE时遇到了类似的问题。


Found out I need to call the below for the plot to show for Spyder.

我发现我需要打下面的电话才能为Spyder展示剧情。


backtesting.set_bokeh_output(notebook=False)

BackTesting.set_bokeh_out(Notebook=False)



I have update Python to version 3.11 & downgrade bokeh to 2.4.3

我已将Python更新到版本3.11,并将bokeh降级到2.4.3


This worked for me.

这对我很管用。



Downgrading Bokeh didn't work for me.
But, after importing backtesting in Jupyter, I needed to do:
backtesting.set_bokeh_output(notebook=False)

降低Bokeh的评级对我来说不管用。但是,在Jupyter中导入回溯测试后,我需要执行以下操作:back test ing.set_bokeh_out(NOTBOOK=FALSE)


The expected plot was then generated in a new interactive browser tab.

然后在新的交互式浏览器选项卡中生成预期的绘图。



I can produce plots after upgrading to 3.3.0 dev1, which solved my problem temporarily - though I still get the "BokehDeprecationWarning: Passing lists of formats for DatetimeTickFormatter scales was deprecated in Bokeh 3.0."

在升级到3.3.0Dev1之后,我可以生成绘图,这暂时解决了我的问题--尽管我仍然得到了“BokehDeposationWarning:传递Datetime TickForMatter Scale的格式列表在Bokeh 3.0中已被弃用”。


更多回答

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com