code: def runstrat(args=None):
      args = parse_args(args)
  
      cerebro = bt.Cerebro()
  
      # Data feed kwargs
      kwargs = dict()
  
      # Parse from/to-date
      dtfmt, tmfmt = "%Y-%m-%d", "T%H:%M:%S"
      for a, d in (
          (getattr(args, x), x) for x in ["fromdate", "todate"]
      ):
          if a:
              strpfmt = dtfmt + tmfmt * ("T" in a)
              kwargs[d] = datetime.datetime.strptime(a, strpfmt)
  
      if not args.offline:
          YahooData = bt.feeds.YahooFinanceData
      else:
          YahooData = bt.feeds.YahooFinanceCSVData
  
      # Data feeds
      data0 = YahooData(dataname=args.data0, **kwargs)
      # cerebro.adddata(data0)
      cerebro.resampledata(data0, timeframe=bt.TimeFrame.Weeks)
  
      data1 = YahooData(dataname=args.data1, **kwargs)
      # cerebro.adddata(data1)
      cerebro.resampledata(data1, timeframe=bt.TimeFrame.Weeks)
      data1.plotinfo.plotmaster = data0
  
      # Broker
      kwargs = eval("dict(" + args.broker + ")")
      cerebro.broker = bt.brokers.BackBroker(**kwargs)
  
      # Sizer
      kwargs = eval("dict(" + args.sizer + ")")
      cerebro.addsizer(bt.sizers.FixedSize, **kwargs)
  
      # Strategy
      if True:
          kwargs = eval("dict(" + args.strat + ")")
          cerebro.addstrategy(MACrossOver, **kwargs)
  
      cerebro.addobserver(
          bt.observers.LogReturns2,
          timeframe=bt.TimeFrame.Weeks,
          compression=20,
      )
  
      # Execute
      cerebro.run(**(eval("dict(" + args.cerebro + ")")))
  
      if args.plot:  # Plot if requested to
          cerebro.plot(**(eval("dict(" + args.plot + ")")))
  
file_path: backtrader/samples/gold-vs-sp500/gold-vs-sp500.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import argparse
  import datetime
  import scipy.stats
  import backtrader
label_desc: Use image node_id 1 for calling a global function with example usage: runstrat(args) without return types