def runstrat(): args = parse_args() # Create a cerebro entity cerebro = bt.Cerebro(stdstats=False) # Add a strategy cerebro.addstrategy(bt.Strategy) # Load the Data datapath = args.dataname or '../../datas/2006-day-001.txt' data = btfeeds.BacktraderCSVData(dataname=datapath) # Handy dictionary for the argument timeframe conversion tframes = dict(daily=bt.TimeFrame.Days, weekly=bt.TimeFrame.Weeks, monthly=bt.TimeFrame.Months) # Resample the data if args.oldrs: data = bt.DataResampler(dataname=data, timeframe=tframes[args.timeframe], compression=args.compression) else: data.resample(timeframe=tframes[args.timeframe], compression=args.compression) # Add the resample data instead of the original cerebro.adddata(data) # Run over everything cerebro.run() # Plot the result cerebro.plot(style='bar')
def test_run(main=False): # for i in [True, False]: for rstype in [True, False]: if rstype: runonces = [True] else: runonces = [True, False] for runonce in runonces: data = testcommon.getdata(0) if rstype: data = bt.DataResampler(dataname=data, timeframe=bt.TimeFrame.Weeks, compression=1) else: data.resample(timeframe=bt.TimeFrame.Weeks, compression=1) datas = [data] testcommon.runtest(datas, testcommon.TestStrategy, main=main, runonce=runonce, plot=main, chkind=chkind, chkmin=chkmin, chkvals=chkvals, chkargs=chkargs)
def runstrat(): args = parse_args() # Create a cerebro entity cerebro = bt.Cerebro(stdstats=False) # Add a strategy if not args.indicators: cerebro.addstrategy(bt.Strategy) else: cerebro.addstrategy( SMAStrategy, # args for the strategy period=args.period, onlydaily=args.onlydaily, ) # Load the Data datapath = args.dataname or '../datas/sample/2006-day-001.txt' data = btfeeds.BacktraderCSVData( dataname=datapath) tframes = dict( daily=bt.TimeFrame.Days, weekly=bt.TimeFrame.Weeks, monthly=bt.TimeFrame.Months) # Handy dictionary for the argument timeframe conversion # Resample the data if args.noresample: datapath = args.dataname2 or '../datas/sample/2006-week-001.txt' data2 = btfeeds.BacktraderCSVData( dataname=datapath) else: data2 = bt.DataResampler( dataname=data, timeframe=tframes[args.timeframe], compression=args.compression) # First add the original data - smaller timeframe cerebro.adddata(data) # And then the large timeframe cerebro.adddata(data2) # Run over everything cerebro.run() # Plot the result cerebro.plot(style='bar')
def test_run(main=False): data = testcommon.getdata(0) data = bt.DataResampler(dataname=data, timeframe=bt.TimeFrame.Weeks, compression=1) datas = [data] testcommon.runtest(datas, testcommon.TestStrategy, main=main, plot=main, chkind=chkind, chkmin=chkmin, chkvals=chkvals, chkargs=chkargs)
def runstrat(): args = parse_args() # Create a cerebro entity cerebro = bt.Cerebro(stdstats=False) # Add a strategy cerebro.addstrategy(testStrategy) # Load the Data datapath = args.dataname or 'D:/backtradertutorial/datas/2006-min-005.txt' data = btfeeds.BacktraderCSVData( dataname=datapath, timeframe=bt.TimeFrame.Minutes,todate=datetime(2006, 1, 3)) # Handy dictionary for the argument timeframe conversion tframes = dict( daily=bt.TimeFrame.Days, weekly=bt.TimeFrame.Weeks, monthly=bt.TimeFrame.Months) # Resample the data if args.oldrs: # Old resampler, fully deprecated data = bt.DataResampler( dataname=data, timeframe=bt.TimeFrame.Minutes, compression=1) # Add the resample data instead of the original cerebro.adddata(data) else: # New resampler print('new resample',tframes[args.timeframe],args.compression,) cerebro.resampledata( data, timeframe=bt.TimeFrame.Minutes, compression=2) # Run over everything cerebro.run()