parser.add_argument("--loglevel", default="INFO", choices=['DEBUG', 'INFO', 'WARNING', 'ERROR']) parser.add_argument("--plot", action="store_true") args = parser.parse_args() logging.basicConfig(level=getattr(logging, args.loglevel)) # Create a cerebro entity cerebro = Cerebro() # Set our desired cash start cerebro.broker.setcash(100000.0) # Set our sizer cerebro.addsizer(PercentSizer, percents=90) # Load the Kraken data pair = args.long + args.short datafeed = KrakenData(dataname=pair, timeframe=getattr(TimeFrame, args.timeframe), compression=args.compression, refresh_period=args.refresh, historical=args.historical, backfill_start=not args.no_backfill) cerebro.adddata(datafeed) # Add the strategies to run cerebro.addstrategy(TestStrategy) # Run the backtest
cerebro.addstrategy(strategy=BBands, BBandsperiod=yearly, DevFactor=devfactor) else: cerebro.addstrategy(strategy=strategies[args.strategy]) # cerebro.addstrategy(strategy=GoldenCross) ## Analyzers cerebro.addanalyzer(bt.analyzers.SharpeRatio, _name='sharpe_ratio') cerebro.addanalyzer(bt.analyzers.Returns, _name='returns') cerebro.addanalyzer(bt.analyzers.DrawDown, _name='drawdown') # Add a FixedSize sizer according to the stake cerebro.broker.setcommission(commission=0.000) # 0.5% of the operation value cerebro.addsizer(bt.sizers.AllInSizer) ## Set up for looping through the stocks # Loop through selected stocks # Download the relevant feed # if strat == 'bbands2': start_date = datetime.datetime(2020, 3, 26) # start_date = datetime.datetime(2016, 4, 1) end_date = datetime.datetime(2021, 1, 27) feed = bt.feeds.YahooFinanceData( dataname=sel_stock[0], # Do not pass values before this date fromdate=start_date, # Do not pass values after this date