code: def parse_args(pargs=""):
      parser = argparse.ArgumentParser(
          description="Backtrader Run Script",
          formatter_class=argparse.RawTextHelpFormatter,
      )
  
      group = parser.add_argument_group(title="Data options")
      # Data options
      group.add_argument(
          "--data",
          "-d",
          action="append",
          required=True,
          help="Data files to be added to the system",
      )
  
      group = parser.add_argument_group(title="Cerebro options")
      group.add_argument(
          "--cerebro",
          "-cer",
          metavar="kwargs",
          required=False,
          const="",
          default="",
          nargs="?",
          help=(
              "The argument can be specified with the following form:\n"
              "\n"
              "  - kwargs\n"
              "\n"
              '    Example: "preload=True" which set its to True\n'
              "\n"
              "The passed kwargs will be passed directly to the cerebro\n"
              "instance created for the execution\n"
              "\n"
              "The available kwargs to cerebro are:\n"
              "  - preload (default: True)\n"
              "  - runonce (default: True)\n"
              "  - maxcpus (default: None)\n"
              "  - stdstats (default: True)\n"
              "  - live (default: False)\n"
              "  - exactbars (default: False)\n"
              "  - preload (default: True)\n"
              "  - writer (default False)\n"
              "  - oldbuysell (default False)\n"
              "  - tradehistory (default False)\n"
          ),
      )
  
      group.add_argument(
          "--nostdstats",
          action="store_true",
          help="Disable the standard statistics observers",
      )
  
      datakeys = list(DATAFORMATS)
      group.add_argument(
          "--format",
          "--csvformat",
          "-c",
          required=False,
          default="btcsv",
          choices=datakeys,
          help="CSV Format",
      )
  
      group.add_argument(
          "--fromdate",
          "-f",
          required=False,
          default=None,
          help="Starting date in YYYY-MM-DD[THH:MM:SS] format",
      )
  
      group.add_argument(
          "--todate",
          "-t",
          required=False,
          default=None,
          help="Ending date in YYYY-MM-DD[THH:MM:SS] format",
      )
  
      group.add_argument(
          "--timeframe",
          "-tf",
          required=False,
          default="days",
          choices=TIMEFRAMES.keys(),
          help="Ending date in YYYY-MM-DD[THH:MM:SS] format",
      )
  
      group.add_argument(
          "--compression",
          "-cp",
          required=False,
          default=1,
          type=int,
          help="Ending date in YYYY-MM-DD[THH:MM:SS] format",
      )
  
      group = parser.add_mutually_exclusive_group(required=False)
  
      group.add_argument(
          "--resample",
          "-rs",
          required=False,
          default=None,
          help="resample with timeframe:compression values",
      )
  
      group.add_argument(
          "--replay",
          "-rp",
          required=False,
          default=None,
          help="replay with timeframe:compression values",
      )
  
      group.add_argument(
          "--hook",
          dest="hooks",
          action="append",
          required=False,
          metavar="module:hookfunction:kwargs",
          help=(
              "This option can be specified multiple times.\n"
              "\n"
              "The argument can be specified with the following form:\n"
              "\n"
              "  - module:hookfunction:kwargs\n"
              "\n"
              "    Example: mymod:myhook:a=1,b=2\n"
              "\n"
              "kwargs is optional\n"
              "\n"
              "If module is omitted then hookfunction will be sought\n"
              "as the built-in cerebro method. Example:\n"
              "\n"
              "  - :addtz:tz=America/St_Johns\n"
              "\n"
              "If name is omitted, then the 1st function found in the\n"
              "mod will be used. Such as in:\n"
              "\n"
              "  - module or module::kwargs\n"
              "\n"
              "The function specified will be called, with cerebro\n"
              "instance passed as the first argument together with\n"
              "kwargs, if any were specified. This allows to customize\n"
              "cerebro, beyond options provided by this script\n\n"
          ),
      )
  
      # Module where to read the strategy from
      group = parser.add_argument_group(title="Strategy options")
      group.add_argument(
          "--strategy",
          "-st",
          dest="strategies",
          action="append",
          required=False,
          metavar="module:name:kwargs",
          help=(
              "This option can be specified multiple times.\n"
              "\n"
              "The argument can be specified with the following form:\n"
              "\n"
              "  - module:classname:kwargs\n"
              "\n"
              "    Example: mymod:myclass:a=1,b=2\n"
              "\n"
              "kwargs is optional\n"
              "\n"
              "If module is omitted then class name will be sought in\n"
              "the built-in strategies module. Such as in:\n"
              "\n"
              "  - :name:kwargs or :name\n"
              "\n"
              "If name is omitted, then the 1st strategy found in the mod\n"
              "will be used. Such as in:\n"
              "\n"
              "  - module or module::kwargs"
          ),
      )
  
      # Module where to read the strategy from
      group = parser.add_argument_group(title="Signals")
      group.add_argument(
          "--signal",
          "-sig",
          dest="signals",
          action="append",
          required=False,
          metavar="module:signaltype:name:kwargs",
          help=(
              "This option can be specified multiple times.\n"
              "\n"
              "The argument can be specified with the following form:\n"
              "\n"
              "  - signaltype:module:signaltype:classname:kwargs\n"
              "\n"
              "    Example: longshort+mymod:myclass:a=1,b=2\n"
              "\n"
              "signaltype may be ommited: longshort will be used\n"
              "\n"
              "    Example: mymod:myclass:a=1,b=2\n"
              "\n"
              "kwargs is optional\n"
              "\n"
              "signaltype will be uppercased to match the defintions\n"
              "fromt the backtrader.signal module\n"
              "\n"
              "If module is omitted then class name will be sought in\n"
              "the built-in signals module. Such as in:\n"
              "\n"
              "  - LONGSHORT::name:kwargs or :name\n"
              "\n"
              "If name is omitted, then the 1st signal found in the mod\n"
              "will be used. Such as in:\n"
              "\n"
              "  - module or module:::kwargs"
          ),
      )
  
      # Observers
      group = parser.add_argument_group(
          title="Observers and statistics"
      )
      group.add_argument(
          "--observer",
          "-ob",
          dest="observers",
          action="append",
          required=False,
          metavar="module:name:kwargs",
          help=(
              "This option can be specified multiple times.\n"
              "\n"
              "The argument can be specified with the following form:\n"
              "\n"
              "  - module:classname:kwargs\n"
              "\n"
              "    Example: mymod:myclass:a=1,b=2\n"
              "\n"
              "kwargs is optional\n"
              "\n"
              "If module is omitted then class name will be sought in\n"
              "the built-in observers module. Such as in:\n"
              "\n"
              "  - :name:kwargs or :name\n"
              "\n"
              "If name is omitted, then the 1st observer found in the\n"
              "will be used. Such as in:\n"
              "\n"
              "  - module or module::kwargs"
          ),
      )
      # Analyzers
      group = parser.add_argument_group(title="Analyzers")
      group.add_argument(
          "--analyzer",
          "-an",
          dest="analyzers",
          action="append",
          required=False,
          metavar="module:name:kwargs",
          help=(
              "This option can be specified multiple times.\n"
              "\n"
              "The argument can be specified with the following form:\n"
              "\n"
              "  - module:classname:kwargs\n"
              "\n"
              "    Example: mymod:myclass:a=1,b=2\n"
              "\n"
              "kwargs is optional\n"
              "\n"
              "If module is omitted then class name will be sought in\n"
              "the built-in analyzers module. Such as in:\n"
              "\n"
              "  - :name:kwargs or :name\n"
              "\n"
              "If name is omitted, then the 1st analyzer found in the\n"
              "will be used. Such as in:\n"
              "\n"
              "  - module or module::kwargs"
          ),
      )
  
      # Analyzer - Print
      group = parser.add_mutually_exclusive_group(required=False)
      group.add_argument(
          "--pranalyzer",
          "-pralyzer",
          required=False,
          action="store_true",
          help=("Automatically print analyzers"),
      )
  
      group.add_argument(
          "--ppranalyzer",
          "-ppralyzer",
          required=False,
          action="store_true",
          help=("Automatically PRETTY print analyzers"),
      )
  
      # Indicators
      group = parser.add_argument_group(title="Indicators")
      group.add_argument(
          "--indicator",
          "-ind",
          dest="indicators",
          metavar="module:name:kwargs",
          action="append",
          required=False,
          help=(
              "This option can be specified multiple times.\n"
              "\n"
              "The argument can be specified with the following form:\n"
              "\n"
              "  - module:classname:kwargs\n"
              "\n"
              "    Example: mymod:myclass:a=1,b=2\n"
              "\n"
              "kwargs is optional\n"
              "\n"
              "If module is omitted then class name will be sought in\n"
              "the built-in analyzers module. Such as in:\n"
              "\n"
              "  - :name:kwargs or :name\n"
              "\n"
              "If name is omitted, then the 1st analyzer found in the\n"
              "will be used. Such as in:\n"
              "\n"
              "  - module or module::kwargs"
          ),
      )
  
      # Writer
      group = parser.add_argument_group(title="Writers")
      group.add_argument(
          "--writer",
          "-wr",
          dest="writers",
          metavar="kwargs",
          nargs="?",
          action="append",
          required=False,
          const="",
          help=(
              "This option can be specified multiple times.\n"
              "\n"
              "The argument can be specified with the following form:\n"
              "\n"
              "  - kwargs\n"
              "\n"
              "    Example: a=1,b=2\n"
              "\n"
              "kwargs is optional\n"
              "\n"
              "It creates a system wide writer which outputs run data\n"
              "\n"
              "Please see the documentation for the available kwargs"
          ),
      )
  
      # Broker/Commissions
      group = parser.add_argument_group(
          title="Cash and Commission Scheme Args"
      )
      group.add_argument(
          "--cash",
          "-cash",
          required=False,
          type=float,
          help="Cash to set to the broker",
      )
      group.add_argument(
          "--commission",
          "-comm",
          required=False,
          type=float,
          help="Commission value to set",
      )
      group.add_argument(
          "--margin",
          "-marg",
          required=False,
          type=float,
          help="Margin type to set",
      )
      group.add_argument(
          "--mult",
          "-mul",
          required=False,
          type=float,
          help="Multiplier to use",
      )
  
      group.add_argument(
          "--interest",
          required=False,
          type=float,
          default=None,
          help="Credit Interest rate to apply (0.0x)",
      )
  
      group.add_argument(
          "--interest_long",
          action="store_true",
          required=False,
          default=None,
          help="Apply credit interest to long positions",
      )
  
      group.add_argument(
          "--slip_perc",
          required=False,
          default=None,
          type=float,
          help="Enable slippage with a percentage value",
      )
      group.add_argument(
          "--slip_fixed",
          required=False,
          default=None,
          type=float,
          help="Enable slippage with a fixed point value",
      )
  
      group.add_argument(
          "--slip_open",
          required=False,
          action="store_true",
          help="enable slippage for when matching opening prices",
      )
  
      group.add_argument(
          "--no-slip_match",
          required=False,
          action="store_true",
          help=(
              "Disable slip_match, ie: matching capped at \n"
              "high-low if slippage goes over those limits"
          ),
      )
      group.add_argument(
          "--slip_out",
          required=False,
          action="store_true",
          help="with slip_match enabled, match outside high-low",
      )
  
      # Output flushing
      group.add_argument(
          "--flush",
          required=False,
          action="store_true",
          help="flush the output - useful under win32 systems",
      )
  
      # Plot options
      parser.add_argument(
          "--plot",
          "-p",
          nargs="?",
          metavar="kwargs",
          default=False,
          const=True,
          required=False,
          help=(
              "Plot the read data applying any kwargs passed\n"
              "\n"
              "For example:\n"
              "\n"
              '  --plot style="candle" (to plot candlesticks)\n'
          ),
      )
  
      if pargs:
          return parser.parse_args(pargs)
  
      return parser.parse_args()
  
file_path: backtrader/backtrader/btrun/btrun.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import argparse
  import datetime
  import inspect
  import itertools
  import random
  import string
  import sys
  import backtrader
label_desc: Use image node_id 11 for calling a global function with example usage: parse_args(pargs) and returns: parser, parser