all data always available when backtesting with a pandas dataframe feed
-
hello,
I'm not sure what I'm doing wrong, I'm implementing an indicator and loading data from a pandas dataframe,
here's how I load the data feed:
data = bt.feeds.PandasData(dataname=pandas, **fxcm.candles_to_backtrader(pandas)) # Add the Data Feed to Cerebro cerebro.adddata(data) # Run over everything cerebro.run()
where
fxcm.candles_to_backtrader(pandas)
is defined as:def candles_to_backtrader(self, candles, ask=True): aob = "ask" if not ask: aob = "bid" return {"name": aob, "open": "%sopen" % aob, "high": "%shigh" % aob, "low": "%slow" % aob, "close": "%sclose" % aob, "volume": "tickqty"}
my indicator is:
import backtrader as bt class Density(bt.Indicator): lines = ('my_indicator',) params = () def next(self): print("new iteration") for i in self.datas[0].close: print("available data %f" % i)
next
gets called many times, and everytime thefor
loop prints all the close values as they were produced bycandles_to_backtrader
method.I'm quite confused, I expected that when backtesting I were to find in datas[0] only an incremental fraction of the input data at each call to
next
.So first call I'd see the oldest values, the second call I'd see the oldest and the following ones, and get the full dataset only at the latest call.
What am I missing here?
thanks.
-
@dongiulio said in all data always available when backtesting with a pandas dataframe feed:
for i in self.datas[0].close:
You are printing the entire buffer instead of addressing a given index.
Suggested reading: Docs - Platform Concepts - Section: Indexing: 0 and -1
-
Hi dongiulio,
I noticed you are using fxcm here. Do you have an fxcm / fxcmpy broker implementation for backtrader that you would be happy to share? I want to use fxcm and hoping to cut down implementation time.