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/

    #ValueError #Invalid #literal for #int() while running #cereber.run()

    General Code/Help
    2
    4
    61
    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.
    • N
      nsananguly last edited by

      Pasting part of my code here . Which is simple moving average crossover. When I run cerebro.run(). I get the following error

      Code:

      cerebro = bt.Cerebro()
      data = bt.feeds.YahooFinanceCSVData(dataname='NIFTYBEES.NS.csv')
      cerebro.adddata(data)
      cerebro.optstrategy(smacross,ma100=100,ma200=200)
      cerebro.broker.setcash(100000)
      cerebro.addsizer(bt.sizers.percents_sizer,percent=25)
      cerebro.addanalyzer(bt.analyzers.SharpeRatio,_name = "Sharpe")
      cerebro.addanalyzer(bt.analyzers.AnnualReturn,_name = "Annual Return")
      cerebro.addanalyzer(bt.analyzers.DrawDown,_name = "Drawdown")
      cerebro.addanalyzer(bt.analyzers.Returns,_name = "Returns")
      cerebro.addanalyzer(bt.analyzers.standarddev,_name= "StdDev")
      cerebro.addanalyzer(bt.analyzers.TimeDrawDown,_name = "Drawdown Time")

      bktest = cerebro.run()
      cerebro.broker.get_value()

      Error that I get is :

      ValueError -> 14 cerebro.run()

      ValueError: invalid literal for int() with base 10: '28-0'

      Seeking guidance on what has gone wrong and how can this be course corrected .

      Tony Shacklock 1 Reply Last reply Reply Quote 0
      • Tony Shacklock
        Tony Shacklock @nsananguly last edited by

        @nsananguly
        Have you tried setting maxcpus=1?
        cerebro.run(maxcpus=1)
        I think this is needed when optimising, but I don't know if it's related to your error.

        N 2 Replies Last reply Reply Quote 1
        • N
          nsananguly @Tony Shacklock last edited by

          @tony-shacklock said in #ValueError #Invalid #literal for #int() while running #cereber.run():

          maxcpus=1

          I actually tried it out. It worked a few times and then started throwing error.

          What I did was give the int() function
          self.adjclose = int(self.data[0].Adjclose)
          and its working for now. Not sure if this will throw up error going further.

          1 Reply Last reply Reply Quote 0
          • N
            nsananguly @Tony Shacklock last edited by

            @tony-shacklock said in #ValueError #Invalid #literal for #int() while running #cereber.run():

            @nsananguly
            Have you tried setting maxcpus=1?
            cerebro.run(maxcpus=1)
            I think this is needed when optimising, but I don't know if it's related to your error.

            I tried it out. Didnt work. But I am sure your suggestion will come handy further down the line. Thanks on that

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