code: def run():
      """Run the code that illustrates the pairs trading strategy"""
      data = make_data()
  
      # Define the "entry" strategy of the trade. In this case, we give each asset unit weight and trade it
      trade_entry = bt.AlgoStack(
          bt.algos.RunOnce(), WeighPair(1.0), bt.algos.Rebalance()
      )
  
      # Define the "exit" strategy of the trade. Here we exit when we cross either an upper/lower
      # threshold on the price of the strategy, or hold it for a fixed length of time.
      trade_exit = bt.AlgoStack(
          bt.algos.Or(
              [
                  PriceCompare(96.0, is_greater=False),
                  PriceCompare(104.0, is_greater=True),
                  bt.algos.RunAfterDays(5),
              ]
          ),
          ClosePositions(),
      )
      # Combine the entry, exit and debug algos for each trade
      trade_algos = [
          bt.algos.Or([trade_entry, trade_exit, DebugTradeLevel()])
      ]
  
      # Define the strategy for the master portfolio.
      strategy_algos = [
          PairsSignal(threshold=4.0, indicator_name="my_indicator"),
          SetupPairsTrades(trade_algos),
          SizePairsTrades(pct_of_capital=0.2),
          DebugPortfolioLevel(),
      ]
  
      # Build and run the strategy
      strategy = bt.Strategy("PairsStrategy", strategy_algos)
      test = bt.Backtest(
          strategy, data, additional_data={"my_indicator": data}
      )
      out = bt.run(test)
      print(out.stats)
      return out
  
imports: from copy import deepcopy
  from future.utils import iteritems
  from datetime import date
  import pandas
  import numpy
  import bt
label_desc: Use image node_id 2 for calling a global function with example usage: run() and returns: out