broker.get_value() return NaN after i add pyfolio analyzer
-
class StrategyTop(bt.Strategy): def notify_timer(self, timer, when, *args, **kwargs): self.broker.get_value()#always return NaN after add dd pyfolio analyzer, no problem for other analyzer. cerebro = bt.Cerebro(stdstats=False) cerebro.addstrategy(StrategyTop) cerebro.adddata(data, name=INDEX) cerebro.adddata(data, name=s) startcash = 10000000 cerebro.broker.setcash(startcash) cerebro.broker.set_checksubmit(False) comminfo = stampDutyCommissionScheme(stamp_duty=0.001, commission=0.001) cerebro.broker.addcommissioninfo(comminfo) print(cerebro.broker.get_value()) #no problem here #cerebro.addanalyzer(bt.analyzers.SharpeRatio, _name = 'SharpeRatio') #cerebro.addanalyzer(bt.analyzers.DrawDown, _name='DW') cerebro.addanalyzer(bt.analyzers.PyFolio, _name='pyfolio') print(cerebro.broker.get_value()) #no problem here
always return NaN(self.broker.get_value()) in strategy object after adding pyfolio analyzer.
any clues? your help will be much appreciated.
-
Getting the same error for pyfolio. Please let me know if you get some help
-
Tried to reproduce it locally using the above script (slightly modified to include the data initialization and
cerebro.run
method). The problem I see is in adding the same data feed object two times (with different name). This resulted in exception:Traceback (most recent call last): File "C:/Users/Vlad/PycharmProjects/test/support_3195.py", line 36, in <module> cerebro.run() File "W:\backtrader\backtrader\cerebro.py", line 1177, in run runstrat = self.runstrategies(iterstrat) File "W:\backtrader\backtrader\cerebro.py", line 1346, in runstrategies self._runonce(runstrats) File "W:\backtrader\backtrader\cerebro.py", line 1744, in _runonce self._brokernotify() File "W:\backtrader\backtrader\cerebro.py", line 1413, in _brokernotify self._broker.next() File "W:\backtrader\backtrader\brokers\bbroker.py", line 1233, in next self._get_value() # update value File "W:\backtrader\backtrader\brokers\bbroker.py", line 439, in _get_value dvalue = comminfo.getvaluesize(position.size, data.close[0]) File "W:\backtrader\backtrader\linebuffer.py", line 163, in __getitem__ return self.array[self.idx + ago] IndexError: array index out of range
but not in Nan value returned from
self.broker.get_value()
method. Changing the code to use different data feeds, like:data_path = os.path.join(bt.__file__, '../../datas/yhoo-1996-2014.txt') data = bt.feeds.YahooFinanceCSVData(dataname=data_path) data1 = bt.feeds.YahooFinanceCSVData(dataname=data_path) cerebro.adddata(data, name="INDEX") cerebro.adddata(data1, name="S")
couldn't repro the issue. Will appreciate if the author could provide the full script with the exact point of failure ( it is better to check for Nan value at that point and raise the exception - please include the backtrace in this case )