code: def benchmark_random(backtest, random_strategy, nsim=100):
      """
      Given a backtest and a random strategy, compare backtest to
      a number of random portfolios.
  
      The idea here is to benchmark your strategy vs a bunch of
      random strategies that have a similar structure but execute
      some part of the logic randomly - basically you are trying to
      determine if your strategy has any merit - does it beat
      randomly picking weight? Or randomly picking the selected
      securities?
  
      Args:
          * backtest (Backtest): A backtest you want to benchmark
          * random_strategy (Strategy): A strategy you want to benchmark
            against. The strategy should have a random component to
            emulate skilless behavior.
          * nsim (int): number of random strategies to create.
  
      Returns:
          RandomBenchmarkResult
  
      """
      # save name for future use
      if backtest.name is None:
          backtest.name = "original"
  
      # run if necessary
      if not backtest.has_run:
          backtest.run()
  
      bts = []
      bts.append(backtest)
      data = backtest.data.dropna()
  
      # create and run random backtests
      for i in tqdm(range(nsim)):
          random_strategy.name = "random_%s" % i
          rbt = bt.Backtest(random_strategy, data)
          rbt.run()
  
          bts.append(rbt)
  
      # now create new RandomBenchmarkResult
      res = RandomBenchmarkResult(*bts)
  
      return res
  
imports: from __future__ import division
  from copy import deepcopy
  import bt
  import ffn
  import pandas
  import numpy
  from matplotlib import pyplot
  import pyprind
  from tqdm import tqdm
label_desc: Use image node_id 2 for calling a global function with example usage: benchmark_random(backtest, random_strategy, nsim) and returns: res