Skip to content

Issue in Class Sentiment #3

@gowrijp

Description

@gowrijp

When you execute cerebro.run() you get the error as given below:
Starting Portfolio Value: 100000.00

TypeError Traceback (most recent call last)
in
147 cerebro.broker.setcommission(commission=0.001)
148 print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
--> 149 cerebro.run()
150 print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
151

~\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:

~\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:

~\Anaconda3\lib\site-packages\backtrader\cerebro.py in _runonce(self, runstrats)
1650 '''
1651 for strat in runstrats:
-> 1652 strat._once()
1653 strat.reset() # strat called next by next - reset lines
1654

~\Anaconda3\lib\site-packages\backtrader\lineiterator.py in _once(self)
295
296 for indicator in self._lineiterators[LineIterator.IndType]:
--> 297 indicator._once()
298
299 for observer in self._lineiterators[LineIterator.ObsType]:

~\Anaconda3\lib\site-packages\backtrader\lineiterator.py in _once(self)
315 # indicators are each called with its min period
316 self.preonce(0, self._minperiod - 1)
--> 317 self.oncestart(self._minperiod - 1, self._minperiod)
318 self.once(self._minperiod, self.buflen())
319

~\Anaconda3\lib\site-packages\backtrader\indicator.py in oncestart_via_nextstart(self, start, end)
122
123 self.advance()
--> 124 self.nextstart()
125
126 def once_via_next(self, start, end):

~\Anaconda3\lib\site-packages\backtrader\lineiterator.py in nextstart(self)
345
346 # Called once for 1st full calculation - defaults to regular next
--> 347 self.next()
348
349 def next(self):

in next(self)
26 self.sentiment = date_sentiment[date]
27 prev_sentiment = self.sentiment
---> 28 self.lines.sentiment[0] = self.sentiment
29
30

~\Anaconda3\lib\site-packages\backtrader\linebuffer.py in setitem(self, ago, value)
220 value (variable): value to be set
221 '''
--> 222 self.array[self.idx + ago] = value
223 for binding in self.bindings:
224 binding[ago] = value

TypeError: must be real number, not LineBuffer

Can you please tell me as to what needs to be changed?
I believe self.sentiment is not defined appropriately due to which the error is arising!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions