code: def main(args=None):
      r"""MarketFlow Main Program
  
      Notes
      -----
      (1) Initialize logging.
      (2) Parse the command line arguments.
      (3) Get the market configuration.
      (4) Get the model configuration.
      (5) Create the model object.
      (6) Call the main MarketFlow pipeline.
  
      Raises
      ------
      ValueError
          Training date must be before prediction date.
  
      """
  
      # Logging
  
      logging.basicConfig(
          format="[%(asctime)s] %(levelname)s\t%(message)s",
          filename="market_flow.log",
          filemode="a",
          level=logging.DEBUG,
          datefmt="%m/%d/%y %H:%M:%S",
      )
      formatter = logging.Formatter(
          "[%(asctime)s] %(levelname)s\t%(message)s",
          datefmt="%m/%d/%y %H:%M:%S",
      )
      console = logging.StreamHandler()
      console.setFormatter(formatter)
      console.setLevel(logging.INFO)
      logging.getLogger().addHandler(console)
  
      # Start the pipeline
  
      logger.info("*" * 80)
      logger.info("MarketFlow Start")
      logger.info("*" * 80)
  
      # Argument Parsing
  
      parser = argparse.ArgumentParser(description="MarketFlow Parser")
      parser.add_argument(
          "--pdate",
          dest="predict_date",
          help="prediction date is in the format: YYYY-MM-DD",
          required=False,
          type=valid_date,
      )
      parser.add_argument(
          "--tdate",
          dest="train_date",
          help="training date is in the format: YYYY-MM-DD",
          required=False,
          type=valid_date,
      )
      parser.add_mutually_exclusive_group(required=False)
      parser.add_argument(
          "--predict", dest="predict_mode", action="store_true"
      )
      parser.add_argument(
          "--train", dest="predict_mode", action="store_false"
      )
      parser.set_defaults(predict_mode=False)
      args = parser.parse_args()
  
      # Set train and predict dates
  
      if args.train_date:
          train_date = args.train_date
      else:
          train_date = pd.datetime(1900, 1, 1).strftime("%Y-%m-%d")
  
      if args.predict_date:
          predict_date = args.predict_date
      else:
          predict_date = datetime.date.today().strftime("%Y-%m-%d")
  
      # Verify that the dates are in sequence.
  
      if train_date >= predict_date:
          raise ValueError(
              "Training date must be before prediction date"
          )
      else:
          logger.info("Training Date: %s", train_date)
          logger.info("Prediction Date: %s", predict_date)
  
      # Read stock configuration file
      market_specs = get_market_config()
  
      # Read model configuration file
  
      model_specs = get_model_config()
      model_specs["predict_mode"] = args.predict_mode
      model_specs["predict_date"] = predict_date
      model_specs["train_date"] = train_date
  
      # Create directories if necessary
  
      output_dirs = [
          "config",
          "data",
          "input",
          "model",
          "output",
          "plots",
          "systems",
      ]
      for od in output_dirs:
          output_dir = SSEP.join([model_specs["directory"], od])
          if not os.path.exists(output_dir):
              logger.info("Creating directory %s", output_dir)
              os.makedirs(output_dir)
  
      # Create a model object from the specifications
      model = Model(model_specs)
  
      # Start the pipeline
      model = market_pipeline(model, market_specs)
  
      # Complete the pipeline
  
      logger.info("*" * 80)
      logger.info("MarketFlow End")
      logger.info("*" * 80)
  
imports: import warnings
  from alphapy.alias import Alias
  from alphapy.analysis import Analysis
  from alphapy.analysis import run_analysis
  from alphapy.data import get_market_data
  from alphapy.globals import PD_INTRADAY_OFFSETS
  from alphapy.globals import PSEP, SSEP
  from alphapy.group import Group
  from alphapy.variables import Variable
  from alphapy.variables import vmapply
  from alphapy.model import get_model_config
  from alphapy.model import Model
  from alphapy.portfolio import gen_portfolio
  from alphapy.space import Space
  from alphapy.system import run_system
  from alphapy.system import System
  from alphapy.utilities import valid_date
  import argparse
  import datetime
  import logging
  import os
  import pandas
  import sys
  import yaml
label_desc: Use image node_id 3 for calling a global function with example usage: main(args) without return types