Commission dependent on direction (buy or sell)



  • My commissions for stocks are 1$ up to 100 units, or 0.01$ per unit if over 100 units.
    In addition exchange charges are 0.05$ on buy, 0.06$ on sell.
    I was able to code the 1st part:

    class CommInfo_My(bt.CommInfoBase):
        params = (
          ('stocklike', True),  # Stocks
          ('commtype', bt.CommInfoBase.COMM_FIXED),  # Apply fixed Commission
        # ('percabs', False),  # pass perc as xx% which is the default
          ('interest_long', True),
        )
    
        def _getcommission(self, size, price, pseudoexec):
            if size <= 100:
                return 1.00
            else:
                return size * self.p.commission
    

    (where I pass commission=0.01)

    But how do I code the 2nd part? Is there a direction indication in the CommInfoBase class?



  • In the original bt code for commission calculations the size variable is used with abs function, so I can assume that short position gives size < 0 and long position gives size > 0. You can directly use it in your new _getcommission fucntion.

    But honestly, it is just 1 cent difference, why not to use 6 cents everywhere?



  • Thanks. So size should be positive for buy and negative for sell (not short)?
    As for the 1c, I suspect it has to do with the time the position is held. I assume it increases with time (never had long lived positions in real life, to verify this). I'll take our advice and add 0.06 to the commissions.



  • @mirono said in Commission dependent on direction (buy or sell):

    Thanks. So size should be positive for buy and negative for sell (not short)?

    From my understanding if you buy, then internally size is positive for trade and commission calcs; if you sell, then size is negative. short is equal to sell if you have nothing to sell, so I assume negative size also, but you know your trading conditions better. anyway, code it and let us know your results.

    As for the 1c, I suspect it has to do with the time the position is held. I assume it increases with time (never had long lived positions in real life, to verify this).

    I don't think so. My understanding that exchange fee is included into brokerage fee and doesn't apply separately. But I can be wrong.


Log in to reply
 

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