简体   繁体   中英

Backtrader fail to show plot graph

I am new to coding, trying to use backtrader to do a simple backtesting process. 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'

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. I used this link to fix the "Fix ImportError from matplotlib.dates" error. I used this link to use the test data ( 2005-2006-day-001.txt ) in the application. 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". The way to avoid this error is to use older matplot version by running the following codes:

pip uninstall matplotlib
pip install matplotlib==3.1.1

Below is the application test image:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM