首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >backtesting.py绘图功能不工作

backtesting.py绘图功能不工作
EN

Stack Overflow用户
提问于 2022-11-06 10:17:11
回答 2查看 339关注 0票数 1

我正在努力学习backtesting.py,当我运行下面的示例代码时,它会弹出这些错误,任何人都可以帮助吗?我试图卸载Bokeh软件包并重新安装一个旧版本,但它不起作用。

代码语言:javascript
运行
复制
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', ...)
代码语言:javascript
运行
复制
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()
EN

回答 2

Stack Overflow用户

发布于 2022-11-12 04:07:39

在GitHub回购:https://github.com/kernc/backtesting.py/issues/803中,出现了一个问题。

发表的评论建议将bokeh的评级下调至2.4.3:

代码语言:javascript
运行
复制
python3 -m pip install bokeh==2.4.3

这对我有用。

票数 2
EN

Stack Overflow用户

发布于 2022-11-14 09:19:01

我也遇到过类似的问题,使用Spyder。

发现我需要调用下面的情节为间谍显示。

backtesting.set_bokeh_output(notebook=False)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74334910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档