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/

    Feature Request: Stamp Duty

    General Discussion
    2
    5
    1298
    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.
    • T
      ThatBlokeDave last edited by

      In the UK, a 0.5% stamp duty applies to stock purchases but not sales.

      This means for the UK market, I will be looking to create a commission scheme which has a mix of COMM_FIXED and COM_PERC for buying and only a COMM_FIXED when selling.

      In other words my broker has a flat fee but I need to take into account the profit killing stamp duty :)

      Not sure how many markets this applies to but it would be useful enhancement for the UK.

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

        There seems to be some misunderstanding here: COMM_FIXED is not a flat-fee commission, but represents a fixed value per item bought (shares, futures, options, ...)

        To put the stamp-duty in place (including a flat-fee) see Docs - User Defined Commissions

        You need to override

        def _getcommission(self, size, price, pseudoexec):
           '''Calculates the commission of an operation at a given price
        
           pseudoexec: if True the operation has not yet been executed
           '''
        

        Where size will be > 0 if the operation is a buy and will be < 0 if you are using sell

        T 1 Reply Last reply Reply Quote 0
        • T
          ThatBlokeDave @backtrader last edited by

          @backtrader

          Ok - I see... I will take a look. Thanks for the pointer!

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

            You would obviously return a fixed amount regardless of size (hence flat) plus the 0.5% stamp duty if size > 0

            1 Reply Last reply Reply Quote 0
            • T
              ThatBlokeDave last edited by

              I only just got around to looking at this again. If anyone else, has the same requirement, the code I developed is as follows:

              class stampDutyCommisionScheme(bt.CommInfoBase):
                  '''
                  This commission scheme uses a fixed commission and stamp duty for share
                  purchases. Share sales are subject only to the fixed commission. 
                  
                  The scheme is intended for trading UK equities on the main market. 
                  '''
                  params = (
                      ('stamp_duty', 0.005),
                      ('commission', 5),
                      ('stocklike', True),
                      ('commtype', bt.CommInfoBase.COMM_FIXED),
                      )
              
                  def _getcommission(self, size, price, pseudoexec):
                      '''
                      If size is greater than 0, this indicates a long / buying of shares.
                      If size is less than 0, it idicates a short / selling of shares.
                      '''
              
                      if size > 0:
                          return self.p.commission + (size * price * self.p.stamp_duty)
                      elif size < 0:
                          return self.p.commission
                      else:
                          return 0 #just in case for some reason the size is 0.
              

              Cheers

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