Transaction Analyzer: price <backtrader.linebuffer.LineBuffer object [...]>
-
Hi,
the output of the analyser gives object str instead of the actual price.
Any idea what I'm doing wrong here?cerebro.addanalyzer(bt.analyzers.Transactions, _name='transactions') d =strat.analyzers.getbyname("transactions").get_analysis() print(d)
One correct and one outputted wrong
OrderedDict(
[(datetime.datetime(1970, 1, 1, 19, 9, 27),
[[23.10281162, 2.05e-05, 0, '', -0.00047360763821]]),
[...]
[[-23.10281162, <backtrader.linebuffer.LineBuffer object at 0x000001847D964400>, 0, '', 0.0005489228040912]]),
[...]]) -
@kjiessar
In the above code sample a run is performed, just tried to put in the relevant informationSome more info not sure if it can help but thought couldn't hurt
Trade:
1970-01-01 19:45:46,-5.0,2.224e-05,0,,0.0001112
1970-01-01 19:45:54,-5.0,<backtrader.linebuffer.LineBuffer object at 0x0000029F82F3DF70>,0,,0.00011485
OHLC
1970-01-01 19:45:53+00:00,1629356760,2.271e-05,2.271e-05,2.271e-05,2.271e-05,0.0,0
1970-01-01 19:45:54+00:00,1629356820,2.279e-05,2.297e-05,2.279e-05,2.297e-05,0.0,0
1970-01-01 19:45:55+00:00,1629356880,2.275e-05,2.275e-05,2.275e-05,2.275e-05,0.0,0
-
And more Information:
GitHub: BT Transaction Analyzerdef next(self): # super(Transactions, self).next() # let dtkey update entries = [] for i, dname in self._idnames: pos = self._positions.get(dname, None) if pos is not None: size, price = pos.size, pos.price if size: entries.append([size, price, i, dname, -size * price]) if entries: self.rets[self.strategy.datetime.datetime()] = entries self._positions.clear()
-
@kjiessar
Aaand again. After long debugging session I found the culprit and it wasn't even in the code I had shown.Errorness:
self.sell(data=self.data0, exectype=bt.Order.Limit, price=self.datas[0].close, size=entry["size"], valid=datetime.timedelta(minutes=self.p.tis))
correct one:
self.sell(data=self.data0, exectype=bt.Order.Limit, price=self.datas[0].close[0], size=entry["size"], valid=datetime.timedelta(minutes=self.p.tis))
Note the proce parameter and the last [0]