[英]Backtrader fail to show plot graph
I am new to coding, trying to use backtrader to do a simple backtesting process.我是编码新手,尝试使用 backtrader 进行简单的回测过程。 I was able to execute the buy and sell, but when i am trying to plot the graph it shows: AttributeError: type object 'Gcf' has no attribute '_set_new_active_manager'
我能够执行买卖,但是当我尝试 plot 时,它显示的图表: AttributeError: type object 'Gcf' has no attribute '_set_new_active_manager'
My code is as below:我的代码如下:
print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
cerebro.run()
print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
cerebro.plot()
See if any one can offer some help, many thanks.看看有没有人可以帮忙,非常感谢。
I wanted to help you by developing a test application.我想通过开发一个测试应用程序来帮助你。 The test application was based on the Plotting application.
测试应用程序基于Plotting应用程序。 I used this link to fix the "Fix ImportError from matplotlib.dates" error.
我使用此链接修复了“从 matplotlib.dates 修复 ImportError”错误。 I used this link to use the test data (
2005-2006-day-001.txt
) in the application.我使用此链接在应用程序中使用测试数据 (
2005-2006-day-001.txt
)。 Below is a demo sample:下面是一个演示示例:
from __future__ import (absolute_import, division, print_function, unicode_literals)
import backtrader as bt
class St(bt.Strategy):
def __init__(self):
self.sma = bt.indicators.SimpleMovingAverage(self.data)
data = bt.feeds.BacktraderCSVData(dataname='dataset.txt')
cerebro = bt.Cerebro()
cerebro.adddata(data)
cerebro.addstrategy(St)
cerebro.run()
cerebro.plot()
Current matplot version causes "Fix ImportError from matplotlib.dates".当前的 matplot 版本导致“从 matplotlib.dates 修复 ImportError”。 The way to avoid this error is to use older matplot version by running the following codes:
避免此错误的方法是通过运行以下代码来使用较旧的 matplot 版本:
pip uninstall matplotlib
pip install matplotlib==3.1.1
Below is the application test image:下面是应用测试图像:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.