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

TypeError: _get_credit_interest() takes 6 positional arguments but 7 were given??



  • Hello,
    I am subclassing _get_credit_interest() as explained in the documentation with the goal to use it to take care of dividends but in runtime I get a TypeError:

    class CommInfo_Stocks(bt.CommInfoBase):
        params = (
          ('percentage',0.019),
          ('min', None),  
          ('max', None), 
          ('stocklike', True),
          ('commtype', bt.CommInfoBase.COMM_PERC),
          ('interest_long', True)
        )
    
        def _getcommission(self, size, price, pseudoexec):
            
            if self.params.percentage is None or self.params.percentage == 0:
                return 0
            
            commission = abs(size) * price * self.params.percentage
            
            if self.params.min is not None and commission < self.params.min:
                commission = self.params.min
                
            if self.params.max is not None and commission > self.params.max:
                commission = self.params.max
    
            return commission
        
        def _get_credit_interest(self, size, price, days, dt0, dt1):
            print('Log Something')
            return 0
    

    This is the log of the error, any hint to fix this?

    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-45-57f80c4d0e3d> in <module>
         59 
         60 # Run
    ---> 61 results = cerebro.run()
         62 
         63 # Statistics
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\backtrader\cerebro.py in run(self, **kwargs)
       1125             # let's skip process "spawning"
       1126             for iterstrat in iterstrats:
    -> 1127                 runstrat = self.runstrategies(iterstrat)
       1128                 self.runstrats.append(runstrat)
       1129                 if self._dooptimize:
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\backtrader\cerebro.py in runstrategies(self, iterstrat, predata)
       1291                     self._runonce_old(runstrats)
       1292                 else:
    -> 1293                     self._runonce(runstrats)
       1294             else:
       1295                 if self.p.oldsync:
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\backtrader\cerebro.py in _runonce(self, runstrats)
       1686                         return
       1687 
    -> 1688             self._brokernotify()
       1689             if self._event_stop:  # stop if requested
       1690                 return
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\backtrader\cerebro.py in _brokernotify(self)
       1358         notification to the strategy
       1359         '''
    -> 1360         self._broker.next()
       1361         while True:
       1362             order = self._broker.get_notification()
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\backtrader\brokers\bbroker.py in next(self)
       1194                 comminfo = self.getcommissioninfo(data)
       1195                 dt0 = data.datetime.datetime()
    -> 1196                 dcredit = comminfo.get_credit_interest(data, pos, dt0)
       1197                 self.d_credit[data] += dcredit
       1198                 credit += dcredit
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\backtrader\comminfo.py in get_credit_interest(self, data, pos, dt)
        270 
        271         return self._get_credit_interest(data, size, price,
    --> 272                                          (dt0 - dt1).days, dt0, dt1)
        273 
        274     def _get_credit_interest(self, data, size, price, days, dt0, dt1):
    
    TypeError: _get_credit_interest() takes 6 positional arguments but 7 were given
    


  • In CommInfoBase class (the one your class is derived from) the _get_credit_interest is defined as:

    def _get_credit_interest(self, data, size, price, days, dt0, dt1):
    

    You are missing the data parameter.



  • Thanks, I hadn't noticed that in the examples in the documentation the subclassing is from CommissionInfo and not CommInfoBase and the signature of _get_credit_interest is different between the two methods!


Log in to reply
 

});