def run_bt_multiple(): cerebro = Cerebro() df = get_pickle('tiingo', 'SPY') data = PandasData(dataname=df) cerebro.adddata(data) cerebro.addanalyzer(Returns) cerebro.optstrategy(StrategyFetcher, idx=[0, 1]) results = cerebro.run() strats = [x[0] for x in results] for i, strat in enumerate(strats): rets = strat.analyzers.returns.get_analysis() print('Strategy {} Name {}:\n - analyzer: {}\n'.format( i, strat.__class__.__name__, rets))
if not args.strategy in strategies: print("Invalid strategy, must select one of {}".format(strategies.keys())) sys.exit() # if args.strategy == 'bbands': if strat == 'bbands1': # cerebro.addstrategy(strategy=strategies[args.strategy], 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)