我无法理解错误 - AttributeError: 'int' object has no attribute 'to_pydatetime',我将不胜感激,如果有人能帮我解决这个问题?
from datetime import date, datetime
import pandas as pd
import backtrader as bt
file_name = 'fromstart/2021 APR NIFTY.txt'
dataframe = pd.read_csv(file_name)
data = bt.feeds.PandasData(
dataname = dataframe,
fromdate = datetime(2021, 1, 1),
todate = datetime(2021, 4, 30),
)
class AllInOne(bt.Strategy):
def __init__(self):
self.dataopen = self.datas[0].open_p # Keep a reference to the "open" line in the data[0] dataseries
self.datahigh = self.datas[0].high_p # Keep a reference to the "high" line in the data[0] dataseries
self.datalow = self.datas[0].low_p # Keep a reference to the "low" line in the data[0] dataseries
self.dataclose = self.datas[0].close_p # Keep a reference to the "close" line in the data[0] dataseries
def next(self):
pass
if __name__ == '__main__' :
cerebro = bt.Cerebro() # We initialize the `cerebro` backtester.
cerebro.adddata(data) # We add the dataset in the Data cell.
cerebro.addstrategy(AllInOne)
print('Starting Portfolio Value: {0:8.2f}'.format(cerebro.broker.getvalue()))
results = cerebro.run()
print('Final Portfolio Value: {0:8.2f}'.format(cerebro.broker.getvalue()))
数据和堆栈跟踪: