For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Broker.get_value() on multiple instruments

  • I have 4 instruments in my bt. I set the commissions for each as follows:, name="intr_0"), name="intr_1")


    Now I want to access the pnl for an individual instrument inside Strategy:[1])

    and I get the following error:

    File "C:\Users\micro\Miniconda3\envs\abc\lib\site-packages\backtrader\", 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!

    Any thoughts?

    Kind regards

  • administrators

    You are passing a data feed instead of an array of data feeds, hence the name datas in 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?

  • administrators

    @deedy said in Broker.get_value() on multiple instruments:

    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.

Log in to reply