code: def market_pipeline(model, market_specs):
      r"""AlphaPy MarketFlow Pipeline
  
      Parameters
      ----------
      model : alphapy.Model
          The model object for AlphaPy.
      market_specs : dict
          The specifications for controlling the MarketFlow pipeline.
  
      Returns
      -------
      model : alphapy.Model
          The final results are stored in the model object.
  
      Notes
      -----
      (1) Define a group.
      (2) Get the market data.
      (3) Apply system features.
      (4) Create an analysis.
      (5) Run the analysis, which calls AlphaPy.
  
      """
  
      logger.info("Running MarketFlow Pipeline")
  
      # Get model specifications
  
      predict_mode = model.specs["predict_mode"]
      target = model.specs["target"]
  
      # Get market specifications
  
      create_model = market_specs["create_model"]
      data_history = market_specs["data_history"]
      features = market_specs["features"]
      forecast_period = market_specs["forecast_period"]
      fractal = market_specs["fractal"]
      functions = market_specs["functions"]
      lag_period = market_specs["lag_period"]
      leaders = market_specs["leaders"]
      predict_history = market_specs["predict_history"]
      target_group = market_specs["target_group"]
  
      # Set the target group
  
      group = Group.groups[target_group]
      logger.info("All Symbols: %s", group.members)
  
      # Determine whether or not this is an intraday analysis.
  
      intraday = any(
          substring in fractal for substring in PD_INTRADAY_OFFSETS
      )
  
      # Get stock data. If we can't get all the data, then
      # predict_history resets to the actual history obtained.
  
      lookback = predict_history if predict_mode else data_history
      npoints = get_market_data(
          model, market_specs, group, lookback, intraday
      )
      if npoints > 0:
          logger.info("Number of Data Points: %d", npoints)
      else:
          raise ValueError("Could not get market data from source")
  
      # Run an analysis to create the model
  
      if create_model:
          logger.info("Creating Model")
          # apply features to all of the frames
          vmapply(group, features, functions)
          vmapply(group, [target], functions)
          # run the analysis, including the model pipeline
          a = Analysis(model, group)
          run_analysis(
              a, lag_period, forecast_period, leaders, predict_history
          )
      else:
          logger.info("No Model (System Only)")
  
      # Run a system
  
      system_specs = market_specs["system"]
      if system_specs:
          # get the system specs
          system_name = system_specs["name"]
          longentry = system_specs["longentry"]
          shortentry = system_specs["shortentry"]
          longexit = system_specs["longexit"]
          shortexit = system_specs["shortexit"]
          holdperiod = system_specs["holdperiod"]
          scale = system_specs["scale"]
          logger.info("Running System %s", system_name)
          logger.info("Long Entry  : %s", longentry)
          logger.info("Short Entry : %s", shortentry)
          logger.info("Long Exit   : %s", longexit)
          logger.info("Short Exit  : %s", shortexit)
          logger.info("Hold Period : %d", holdperiod)
          logger.info("Scale       : %r", scale)
          # create and run the system
          system = System(
              system_name,
              longentry,
              shortentry,
              longexit,
              shortexit,
              holdperiod,
              scale,
          )
          tfs = run_system(model, system, group, intraday)
          # generate a portfolio
          gen_portfolio(model, system_name, group, tfs)
  
      # Return the completed model
      return model
  
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 2 for calling a global function with example usage: market_pipeline(model, market_specs) and returns: model