Failing to plot data from Pandas Datafeed(*Please help QAQ stuck for 2 days)
-
Hi guys,
I'm fairly new to backtrader, and I was given this project to build a backtester for a simple strategy. I have already cropped out some data from my main data-sample set(it's about size 100 but I'll only post part of it here so it doesn't take too much space), and tried to search online as much as possible for this problem, but when I try to execute the code below(I've also pasted my pandas dataframe):
My code:
from future import (absolute_import, division, print_function,
unicode_literals)
import argparse
import backtrader as bt
import backtrader.feeds as btfeeds
import datetime
import pandasclass PandasData(bt.feeds.DataBase):
params = ( # Possible values for datetime (must always be present) # None : datetime is the "index" in the Pandas Dataframe # -1 : autodetect position or case-wise equal name # >= 0 : numeric index to the colum in the pandas dataframe # string : column name (as index) in the pandas dataframe ('datetime', None), # Possible values below: # None : column not present # -1 : autodetect position or case-wise equal name # >= 0 : numeric index to the colum in the pandas dataframe # string : column name (as index) in the pandas dataframe ('open', 'open'), ('high', 'high'), ('low', 'low'), ('close', 'close'), ('volume', None), ('openinterest', None), )
cerebro = bt.Cerebro()
file_path = 'tester_v1.csv'
btc_5min = pandas.read_csv(file_path,parse_dates=['date'],index_col=0)
print(btc_5min)class quickStrategy(bt.Strategy):
def init(self):
self.dataclose = self.datas[0].closedef next(self): if self.dataclose[0] < self.dataclose[-1]: if self.dataclose[-1] < self.dataclose[-2]: self.buy()
cerebro.addstrategy(quickStrategy)
data = btfeeds.PandasData(dataname = btc_5min,timeframe = bt.TimeFrame.Minutes)
cerebro.broker.set_cash(10000)
cerebro.adddata(data)
print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
cerebro.run()
cerebro.plot(volume=False)
print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())My pandas Dataframe:
date, open, high, low, close
2021-03-18 00:06:00,59427.64,59561.54,59159.92,59422.37
2021-03-18 00:01:00,59200.26,59267.62,58767.93,59191.35
2021-03-17 23:56:00,58734.82,58835.85,58626.63,58819.72
2021-03-17 23:51:00,58678.56,58734.0,58596.68,58688.36
2021-03-17 23:46:00,58585.78,58608.71,58468.66,58603.43
2021-03-17 23:41:00,58535.1,58592.0,58459.66,58481.24
2021-03-17 23:36:00,58459.41,58549.51,58313.17,58461.21
2021-03-17 23:31:00,58562.45,58612.8,58490.08,58540.19I get this error below:
"Locator attempting to generate 9504000003 ticks ([81647999999.0, ..., 91152000001.0]), which exceeds Locator.MAXTICKS (1000). Killed: 9"I have no idea what's going on. I would really appreciate any helps or ideas on how to resolve it.
Thanks a lot!