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

Feature Request: Stamp Duty

  • 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.

  • administrators

    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

  • @backtrader

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

  • administrators

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

  • 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
                return 0 #just in case for some reason the size is 0.


Log in to reply

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.