Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Extending Commissions

    Blog
    3
    5
    1558
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      backtrader administrators last edited by

      Use the link below to go the original post

      Click here to see the full blog post

      1 Reply Last reply Reply Quote 0
      • t1user
        t1user last edited by

        How can I use it to trade a portfolio of futures? Every contract has a different multiplier and different margin. So multiplier and margin should be linked to data rather than broker. Or is there another way to do it?

        1 Reply Last reply Reply Quote 0
        • A
          ab_trader last edited by

          Commissions can be added to bt with relation to data feed names:

          for index, contract in FUT_SPECS.iterrows():
          
              data = <add data feed with the name=contract['name']>
          
              cerebro.adddata(data)
          
              cerebro.broker.setcommission(commission=float(contract['comm']),
                                              margin=float(contract['margin']),
                                              mult=float(contract['mult']),
                                              name=contract['name'])
          

          FUT_SPECS pandas data frame has comm, margin, mult and name columns.

          • If my answer helped, hit reputation up arrow at lower right corner of the post.
          • Python Debugging With Pdb
          • New to python and bt - check this out
          1 Reply Last reply Reply Quote 1
          • B
            backtrader administrators last edited by

            As indicated by @ab_trader in his/her snippet, the key is the name that you assign to the data feed and which helps you link a given set of details for a commission scheme to that data feed.

            In the snippet, the commission scheme is added directly with setcommission, but you can also create your own instances of CommissionInfo and use addcommissioninfo. See: Docs - Broker

            1 Reply Last reply Reply Quote 0
            • t1user
              t1user last edited by

              That's very helpful. Thank you @ab_trader and @backtrader

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors