code: def runstrat(args=None):
      args = parse_args(args)
  
      cerebro = bt.Cerebro()
      cerebro.broker.set_cash(args.cash)
  
      dkwargs = dict()
      if args.fromdate:
          fromdate = datetime.datetime.strptime(
              args.fromdate, "%Y-%m-%d"
          )
          dkwargs["fromdate"] = fromdate
  
      if args.todate:
          todate = datetime.datetime.strptime(args.todate, "%Y-%m-%d")
          dkwargs["todate"] = todate
  
      if args.timeframe:
          dkwargs["timeframe"] = _TFRAMES[args.timeframe]
  
      if args.compression:
          dkwargs["compression"] = args.compression
  
      # data0 = bt.feeds.BacktraderCSVData(dataname=args.data0, **dkwargs)
      data0 = bt.feeds.VCData(
          dataname=args.data0, historical=True, **dkwargs
      )
      cerebro.adddata(data0, name="Data0")
  
      cerebro.addstrategy(
          St, short=args.short, printdata=args.printdata
      )
      cerebro.addsizer(bt.sizers.FixedSize, stake=args.stake)
  
      # Own analyzerset
      cerebro.addanalyzer(
          bt.analyzers.TimeReturn, timeframe=bt.TimeFrame.Years
      )
      cerebro.addanalyzer(
          bt.analyzers.SharpeRatio, timeframe=bt.TimeFrame.Years
      )
      cerebro.addanalyzer(
          bt.analyzers.SQN,
      )
  
      if args.pyfolio:
          cerebro.addanalyzer(
              bt.analyzers.PyFolio,
              _name="pyfolio",
              timeframe=_TFRAMES[args.pftimeframe],
          )
  
      if args.printout:
          print("Start run")
      results = cerebro.run()
      if args.printout:
          print("End Run")
      strat = results[0]
  
      # Results of own analyzers
      al = strat.analyzers.timereturn
      print("-- Time Return:")
      for k, v in al.get_analysis().items():
          print("{}: {}".format(k, v))
  
      al = strat.analyzers.sharperatio
      print("-- Sharpe Ratio:")
      for k, v in al.get_analysis().items():
          print("{}: {}".format(k, v))
  
      al = strat.analyzers.sqn
      print("-- SQN:")
      for k, v in al.get_analysis().items():
          print("{}: {}".format(k, v))
  
      if args.pyfolio:
          pyfoliozer = strat.analyzers.getbyname(
              "pyfolio",
          )
  
          (
              returns,
              positions,
              transactions,
              gross_lev,
          ) = pyfoliozer.get_pf_items()
          if args.printout:
              print("-- RETURNS")
              print(returns)
              print("-- POSITIONS")
              print(positions)
              print("-- TRANSACTIONS")
              print(transactions)
              print("-- GROSS LEVERAGE")
              print(gross_lev)
  
          if True:
              import pyfolio as pf
  
              pf.create_full_tear_sheet(
                  returns,
                  positions=positions,
                  transactions=transactions,
                  gross_lev=gross_lev,
                  round_trips=True,
              )
  
      if args.plot:
          pkwargs = dict(style="bar")
          if args.plot is not True:  # evals to True but is not True
              pkwargs = eval(
                  "dict(" + args.plot + ")"
              )  # args were passed
  
          cerebro.plot(**pkwargs)
  
file_path: backtrader/samples/pyfolio2/pyfoliotest.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import argparse
  import collections
  import datetime
  import backtrader
label_desc: Use image node_id 1 for calling a global function with example usage: runstrat(args) without return types