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/

    TypeError: __init__() got an unexpected keyword argument 'size'

    General Code/Help
    4
    5
    2879
    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.
    • Ross Coates
      Ross Coates last edited by

      Hi, normally i can solve these sorts of problems for myself but this time i just can't work it out, hopefuly someone here can help. i get this error when trying to run a simple backtest, no optimisation or anything
      '''
      Traceback (most recent call last):
      File "C:/Users/ross_/PycharmProjects/MA-Cross/backtest-1m.py", line 60, in <module>
      strat_list = cerebro.run()
      File "C:\Users\ross_\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\cerebro.py", line 1127, in run
      runstrat = self.runstrategies(iterstrat)
      File "C:\Users\ross_\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\cerebro.py", line 1217, in runstrategies
      strat = stratcls(*sargs, **skwargs)
      File "C:\Users\ross_\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\metabase.py", line 88, in call
      _obj, args, kwargs = cls.doinit(obj, *args, **kwargs)
      File "C:\Users\ross
      \AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\metabase.py", line 78, in doinit
      _obj.init(*args, **kwargs)
      TypeError: init() got an unexpected keyword argument 'size'
      '''

      Thanks

      B 1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        Based on the info shown - it is definitely the bug in your code somewhere. So, we have two options. We can wait for the mind reader, and he can read your code from your mind and find the bug. Or you can post your code and then regular members can try to find the bug. You choose.

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        1 Reply Last reply Reply Quote 0
        • vbs
          vbs last edited by

          I guess you are trying to instantiate your strategy with an argument size which is unknown to your strategy?
          But still, debugging code is alot easier when you actually can see the code in question :)

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

            @Ross-Coates said in TypeError: __init__() got an unexpected keyword argument 'size':

            Hi, normally i can solve these sorts of problems for myself but this time i just can't work it out, hopefuly someone here can help. i get this error when trying to run a simple backtest, no optimisation or anything

            @vbs and @ab_trader have already given the right tips. You probably haven't defined a parameter named size but you pass it in any case.

            It is actually impossible to know, since you only provide an error trace and not actual sample code.

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

              @Ross-Coates said in TypeError: __init__() got an unexpected keyword argument 'size':

              '''

              In any case let me point out that those three ticks (i.e ' vertical) are not backticks as in `

              You may want to directly copy the ticks from the announcement at the top of the forum

              For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
              
              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors