Memory Error Plotting (Ticks)
-
Hey, any idea what i can do ? When plotting (see last line of script) I get :
MemoryError Traceback (most recent call last) <ipython-input-17-2cb10347888b> in <module> 551 552 #Finally plot the end results --> 553 cerebro.plot(style='bar',volume=False) 554 555 # Print out the final result c:\users\ben\appdata\local\programs\python\python37\lib\site-packages\backtrader\cerebro.py in plot(self, plotter, numfigs, iplot, start, end, width, height, dpi, tight, use, **kwargs) 989 rfig = plotter.plot(strat, figid=si * 100, 990 numfigs=numfigs, iplot=iplot, --> 991 start=start, end=end, use=use) 992 # pfillers=pfillers2) 993 c:\users\ben\appdata\local\programs\python\python37\lib\site-packages\backtrader\plot\plot.py in plot(self, strategy, figid, numfigs, iplot, start, end, **kwargs) 218 downinds=self.dplotsdown[ind]) 219 --> 220 self.plotdata(data, self.dplotsover[data]) 221 222 for ind in self.dplotsdown[data]: c:\users\ben\appdata\local\programs\python\python37\lib\site-packages\backtrader\plot\plot.py in plotdata(self, data, indicators) 722 colorup=self.pinf.sch.barup, 723 colordown=self.pinf.sch.bardown, --> 724 label=datalabel) 725 726 self.pinf.zorder[ax] = plotted[0].get_zorder() c:\users\ben\appdata\local\programs\python\python37\lib\site-packages\backtrader\plot\finance.py in plot_ohlc(ax, x, opens, highs, lows, closes, colorup, colordown, width, tickwidth, alpha, label, **kwargs) 508 alpha, 509 label, --> 510 **kwargs) 511 512 return handler.barcol, handler.opencol, handler.closecol c:\users\ben\appdata\local\programs\python\python37\lib\site-packages\backtrader\plot\finance.py in __init__(self, ax, x, opens, highs, lows, closes, colorup, colordown, width, tickwidth, alpha, label, **kwargs) 386 width=width, tickwidth=tickwidth, 387 label=label, --> 388 **kwargs) 389 390 self.barcol = bcol c:\users\ben\appdata\local\programs\python\python37\lib\site-packages\backtrader\plot\finance.py in barcollection(self, xs, opens, highs, lows, closes, width, tickwidth, label, scaling, bot, **kwargs) 463 antialiaseds=useaa, 464 label=label, --> 465 **kwargs) 466 467 def tickopen(i, open): c:\users\ben\appdata\local\programs\python\python37\lib\site-packages\matplotlib\collections.py in __init__(self, segments, linewidths, colors, antialiaseds, linestyles, offsets, transOffset, norm, cmap, pickradius, zorder, facecolors, **kwargs) 1331 **kwargs) 1332 -> 1333 self.set_segments(segments) 1334 1335 def set_segments(self, segments): c:\users\ben\appdata\local\programs\python\python37\lib\site-packages\matplotlib\collections.py in set_segments(self, segments) 1346 _segments = self._add_offsets(_segments) 1347 -> 1348 self._paths = [mpath.Path(_seg) for _seg in _segments] 1349 self.stale = True 1350 c:\users\ben\appdata\local\programs\python\python37\lib\site-packages\matplotlib\collections.py in <listcomp>(.0) 1346 _segments = self._add_offsets(_segments) 1347 -> 1348 self._paths = [mpath.Path(_seg) for _seg in _segments] 1349 self.stale = True 1350 MemoryError:
the script is using Tickdata (for accuracy purposes), but its getting signals from Minutely Bars.
Data is not more than 2 weeks, but even need more.
Is it possible to plot it in Upsampled Bars, to save memory?
Here is the script:if using_TickData == False: Backtraderfilename = BarBackTraderFileName elif using_TickData == True: Backtraderfilename = "Backtrader TickData/TicksSampledForTimeFrame/"+TickBackTraderFileName+"_"+TimeFrame if __name__ == '__main__': cerebro = bt.Cerebro(stdstats=False,optreturn=True,optdatas=True) # Create a cerebro entity if using_TickData == False: data = btfeed.GenericCSVData(dataname=Backtraderfilename, fromdate=datetime.datetime(from_year,from_month,from_day,from_hour,from_minute),#(1999,1,13, 10), todate=datetime.datetime(to_year,to_month,to_day,to_hour,to_minute),#2019,5,1, 20),#(2019,5,1, 20), nullvalue=0.0,dtformat=('%Y.%m.%d %H:%M:%S'), timeframe = bt.TimeFrame.Minutes, compression = 60, datetime=0,high=1,low=2,open=3,close=4,volume=5,openinterest=-1) # Add the Data Feed to Cerebro cerebro.adddata(data) elif using_TickData: #import argparse #args = parse_args() Backtraderfilename = BarBackTraderFileName data = bt.feeds.GenericCSVData(dataname="Backtrader TickData/TicksSampledForTimeFrame/"+TickBackTraderFileName+"_"+TimeFrame, dtformat=('%Y-%m-%d %H:%M:%S'), timeframe=bt.TimeFrame.Ticks, fromdate=datetime.datetime(from_year,from_month,from_day,from_hour,from_minute),#fromdate=datetime.datetime(2019,5,25,0,2), todate=datetime.datetime(to_year,to_month,to_day,to_hour,to_minute),#todate=datetime.datetime(2019,5,30,23), datetime=1,high=2,low=2,open=2,close=2,volume=-1,openinterest=-1) cerebro.adddata(data) # Add a strategy cerebro.addstrategy(TestStrategy) # Add the analyzers we are interested in #cerebro.addanalyzer(bt.analyzers.TradeAnalyzer, _name="ta") #cerebro.addanalyzer(bt.analyzers.SQN, _name="sqn") #cerebro.addanalyzer(bt.analyzers.SQN, _name="dd") # Set our desired cash start cerebro.broker.setcash(StartCash) #slippage cerebro.broker = bt.brokers.BackBroker(slip_perc=0) # 0.5% # Add a FixedSize sizer according to the stake #was ist ein stake? eine Unit-Y 1000 = 0.01 Lot cerebro.addsizer(bt.sizers.FixedSize, stake=VolumeSize) # Set the commission cerebro.broker.setcommission(commission=0) # Print out the starting conditions print('Starting Portfolio Value: %.3f' % cerebro.broker.getvalue()) # Run over everything StrategyResult = cerebro.run() # print the analyzers #printTradeAnalysis(StrategyResult[0].analyzers.ta.get_analysis()) #printSQN(StrategyResult[0].analyzers.sqn.get_analysis()) #printDrawDown(StrategyResult[0].analyzers.dd.get_analysis()) # Print out the final result print('Final Portfolio Value: %.3f' % cerebro.broker.getvalue()) #Finally plot the end results cerebro.plot(style='bar',volume=False) # Print out the final result print('Final Portfolio Value: %.3f' % cerebro.broker.getvalue())
-
@Bayne said in Memory Error Plotting (Ticks):
Data is not more than 2 weeks, but even need more.
Buy a PC with more memory and you will be able to plot more (OS may impose limits on memory allocation)
@Bayne said in Memory Error Plotting (Ticks):
Is it possible to plot it in Upsampled Bars, to save memory?
It will obviously use less room. But you won't see the ticks.
-
@backtrader
I mean, is it possible to backtest on Ticks (like above) but resample the Data only in plot?