Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. nsananguly
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    N
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 8
    • Best 0
    • Groups 0

    nsananguly

    @nsananguly

    0
    Reputation
    1
    Profile views
    8
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    nsananguly Unfollow Follow

    Latest posts made by nsananguly

    • RE: #module #object #not callable

      @vladisld
      I did the following as suggested by you.
      a12047d4-aa85-40cf-8941-85144f22644e-image.png

      When I run cerebro.run(maxcpus=1) I see is the following error:

      3b827ae5-e60c-4b91-a782-d3d4f581c1bc-image.png 'float' object has no attribute 'Adjclose'

      I did check for the data using a simple pandas dataframe it looks good to me
      print(niftbess.Adjclose.describe()),sum(niftbess.Adjclose.isnull())

      output:

      count 248.000000
      mean 157.020363
      std 17.516396
      min 115.760000
      25% 146.550000
      50% 158.610000
      75% 169.332500
      max 192.650000
      Name: Adjclose, dtype: float64

      posted in General Code/Help
      N
      nsananguly
    • RE: #module #object #not callable

      @vladisld

      Would bother for another help. I have done the changes as suggested by you I am not getting the following error.

      The only change is did was the following

      bktest = cerebro.run(maxcpus=1)

      ===============================================
      17 cerebro.addanalyzer(bt.analyzers.TimeDrawDown,_name = "Drawdown Time")
      18
      ---> 19 bktest = cerebro.run(maxcpus=1)
      20
      21 end_portfolio_value = cerebro.broker.getvalue()

      TypeError: init() got an unexpected keyword argument 'period'

      If I remove the maxcpus=1 from the function
      bktest = cerebro.run()
      I get the following error:

      TypeError: cannot pickle 'module' object

      posted in General Code/Help
      N
      nsananguly
    • RE: #module #object #not callable

      @vladisld Thanks . That helped.

      posted in General Code/Help
      N
      nsananguly
    • #module #object #not callable

      I am trying to run the following strategy on Nippon NIFTY BEES and while trying to run the main program getting the following error. I am running the code on VScode platform.Any help is highly appreciated.

      class smacross(bt.SignalStrategy):

      #params = (('fast',100),('slow',200))
      
      def __init__(self):
          self.adjclose = int(float(self.data[0].Adjclose))
          self.sma100 = bt.ind.SimpleMovingAverage(self.adjclose,period=100)
          self.sma200 = bt.ind.SimpleMovingAverage(self.adjclose,period=200)
      
          #Checking to see if the 'adjclose' is greater than sma100 and sma200
          up_over_sma = self.adjclose > self.sma100
          up_over_ema = self.adjclose > self.sma200
      
          down_over_sma = self.adjclose < self.sma100
          down_over_ema = self.adjclose < self.sma200
      
      
      
         
          # Objective is to check if sma100 is greater than sma200
          sma_ema_diff = self.adjclose - self.sma200
          
          #self.crossover = bt.ind.CrossOver(sma1,sma2)
          #Buy signal is given if adjclose > sma100 & adjclose >sma200 and sm100-sma200 >0
          #Sell signal is given is adjclose < sma200 and adjclose-sma200 < 0
          self.buy_signal = bt.And(up_over_sma,up_over_ema,sma_ema_diff > 0)
          self.sell_signal = bt.And(down_over_ema,sma_ema_diff < 0)
          
          self.signal_add(bt.SIGNAL_LONG,self.buy_signal)
          self.signal_add(bt.SIGNAL_SHORT,self.sell_signal)
      

      cerebro = bt.cerebro()
      cerebro.optstrategy(smacross,period=(100,200))
      cerebro.broker.setcash(200000.0)
      cerebro.addsizer(bt.sizers.percents_sizer,percent=25)

      data = bt.feeds.YahooFinanceCSVData(dataname='NIFTYBEES.csv')
      cerebro.adddata(data)

      #if name == 'main':

      start_portfolio_value = cerebro.broker.getvalue()
      print('Starting portfolio value is Rs %s' % start_portfolio_value)

      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.standarddev,_name= "StdDev")
      cerebro.addanalyzer(bt.analyzers.TimeDrawDown,_name = "Drawdown Time")

      bktest = cerebro.run()

      end_portfolio_value = cerebro.broker.getvalue()
      pnl = end_portfolio_value - start_portfolio_value

      print('Ending portfolio value is Rs %s' % end_portfolio_value )
      print("PnL is Rs %s" % pnl)

      Error shown:


      TypeError Traceback (most recent call last)
      <ipython-input-14-fee156ded6a0> in <module>
      ----> 1 cerebro = bt.cerebro()
      2 cerebro.optstrategy(smacross,period=(100,200))
      3 cerebro.broker.setcash(200000.0)
      4 cerebro.addsizer(bt.sizers.percents_sizer,percent=25)
      5

      TypeError: 'module' object is not callable

      posted in General Code/Help
      N
      nsananguly
    • RE: #ValueError #Invalid #literal for #int() while running #cereber.run()

      @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

      posted in General Code/Help
      N
      nsananguly
    • RE: #ValueError #Invalid #literal for #int() while running #cereber.run()

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

      posted in General Code/Help
      N
      nsananguly
    • RE: cerebro.run ValueError: invalid literal for int() with base 10

      @atori Can you suggest what did you do to correct the error ?
      I am also facing the same error.

      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 .

      posted in General Code/Help
      N
      nsananguly
    • #ValueError #Invalid #literal for #int() while running #cereber.run()

      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 .

      posted in General Code/Help
      N
      nsananguly