Navigation

    Backtrader Community

    • Register
    • 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/

    Fixed Commission Amount

    General Code/Help
    3
    4
    521
    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.
    • G
      gionno last edited by

      Hello,

      is there a way to set the commission per movement to a fixed amount?
      E.g. My broker charges 10€ for orders of less of 10k€ and 20€ for larger ones.

      I did not manage to implement this after reading the documentation.

      1 Reply Last reply Reply Quote 0
      • run-out
        run-out last edited by

        There's a good example here. Fixed Income Scheme

        A class is created as follows:

        class FixedCommisionScheme(bt.CommInfoBase):
            '''
            This is a simple fixed commission scheme
            '''
            params = (
                ('commission', 5),
                ('stocklike', True),
                ('commtype', bt.CommInfoBase.COMM_FIXED),
                )
        
            def _getcommission(self, size, price, pseudoexec):
                return self.p.commission
        

        You could modify the _getcommission method to read something like:

            def _getcommission(self, size, price, pseudoexec):
                if abs(size * price) < 10000:
                    return 10
                else:
                    return 20
        

        Once made, add this to cerebro:

        #Set commissions
        comminfo = FixedCommisionScheme()
        cerebro.broker.addcommissioninfo(comminfo)
        

        RunBacktest.com

        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators last edited by

          There is an entire article about this: https://www.backtrader.com/blog/posts/2015-11-20-commission-schemes-subclassing/commission-schemes-subclassing/

          1 Reply Last reply Reply Quote 1
          • G
            gionno last edited by

            Thank you guys super helpful!

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