Broker.get_value() on multiple instruments
I have 4 instruments in my bt. I set the commissions for each as follows:
Now I want to access the pnl for an individual instrument inside Strategy:
and I get the following error:
File "C:\Users\micro\Miniconda3\envs\abc\lib\site-packages\backtrader\broker.py", line 80, in getcommissioninfo
if data._name in self.comminfo:
AttributeError: 'float' object has no attribute '_name'
stepping through the code at:
def getcommissioninfo(self, data)
data is actually a price!
You are passing a data feed instead of an array of data feeds, hence the name
datasin plural, (even if wrong in English) to make it clear what you have to pass.
Thank you BT. So I should write:
this returns the total portfolio. I was hoping to get a list or dict of individual instrument values
@backtrader - sorry to bother you about this again, but is how the function is supposed to work?
If you pass the complete list of data feeds, you will get the value of the complete portfolio.
If you pass an iterable with less data feeds, you will get only the value for the data feeds included in that iterable.
If you pass an iterable with one data feed, you will get only the value for the included data feed.