Hello,
I have a python strategy that is working pretty well. I created my own backtest in python and it is showing good results. In order to reconfirm my results and obtain multiple ratios about the strategy I am trying to implement Backtrater.
My problem is related to the pandas Datafeed. I am retrieving the data from Oanda, and I am only retrieving the basic columns to test the pandas Datafeed. Here the code:
import backtrader.feeds as btfeed
# =============================================================================
# class PandasData(btfeed.PandasData):
# datetime=0,
# time=1,
# open=2,
# high=3,
# low=4,
# close=5,
# volume=6,
# openinterest=-1
#
# =============================================================================
class PandasData(bt.feeds.PandasData):
# lines = ('Time',)
params = (
('datetime', 'Datetime'),
('open','Open'),
('high','High'),
('low','Low'),
('close','Close'),
('volume','Volume'),
('openinterest',None),
# ('Time', 'Time'),
)
#df = bt.feeds.PandasData(dataname=data)
df2=PandasData(dataname=df)
cerebro.adddata(df2)
cerebro.run()
code_text
The error that I am getting is the following:
class PandasData(bt.feeds.PandasData):
# lines = ('Time',)
params = (
('datetime', 'Datetime'),
('open','Open'),
('high','High'),
('low','Low'),
('close','Close'),
('volume','Volume'),
('openinterest',None),
# ('Time', 'Time'),
)
#df = bt.feeds.PandasData(dataname=data)
df2=PandasData(dataname=df)
cerebro.adddata(df2)
cerebro.run()
Traceback (most recent call last):
File "C:\Users\giaco\AppData\Local\Temp/ipykernel_14740/920099771.py", line 18, in <module>
cerebro.run()
File "C:\Users\giaco\anaconda3\lib\site-packages\backtrader\cerebro.py", line 1127, in run
runstrat = self.runstrategies(iterstrat)
File "C:\Users\giaco\anaconda3\lib\site-packages\backtrader\cerebro.py", line 1212, in runstrategies
data.preload()
File "C:\Users\giaco\anaconda3\lib\site-packages\backtrader\feed.py", line 438, in preload
while self.load():
File "C:\Users\giaco\anaconda3\lib\site-packages\backtrader\feed.py", line 479, in load
_loadret = self._load()
File "C:\Users\giaco\anaconda3\lib\site-packages\backtrader\feeds\pandafeed.py", line 268, in _load
dt = tstamp.to_pydatetime()
AttributeError: 'numpy.int64' object has no attribute 'to_pydatetime'code_text
I know that the error is related to the DateTime column. Here the data:
[4460 rows x 6 columns]
Datetime Open ... Close Volume
0 2022-03-01T12:00:00.000000000Z 1.84334 ... 1.84286 1.84334
1 2022-03-01T12:15:00.000000000Z 1.84286 ... 1.84408 1.84286
2 2022-03-01T12:30:00.000000000Z 1.84408 ... 1.84512 1.84408
3 2022-03-01T12:45:00.000000000Z 1.84512 ... 1.84402 1.84512
4 2022-03-01T13:00:00.000000000Z 1.84401 ... 1.84482 1.84401
... ... ... ... ...
4455 2022-05-04T21:15:00.000000000Z 1.73933 ... 1.74036 1.73933
4456 2022-05-04T21:30:00.000000000Z 1.74038 ... 1.74132 1.74038
4457 2022-05-04T21:45:00.000000000Z 1.74114 ... 1.74106 1.74114
4458 2022-05-04T22:00:00.000000000Z 1.74096 ... 1.74106 1.74096
4459 2022-05-04T22:15:00.000000000Z 1.74110 ... 1.73914 1.74110code_text
I have tried to extract the date and the time and format them from the Datetime column and use the Datafeed without any success either. I am using a 15 Minutes timeframe for the forex pair GBP_AUD. I have spent several hours searching the internet as welll as this community and I found some info that other users faced similar problems but they didn't get any answers.
I will appreciate very much any help about this issue.
Thank you very much.