code: def test_variances_and_selection(spa_data):
      adj_models = spa_data.models + linspace(-2, 0.5, spa_data.k)
      spa = SPA(spa_data.benchmark, adj_models, block_size=10, reps=10)
      with pytest.warns(FutureWarning):
          spa.seed(23456)
      spa.compute()
      variances = spa._loss_diff_var
      loss_diffs = spa._loss_diff
      demeaned = spa._loss_diff - loss_diffs.mean(0)
      t = loss_diffs.shape[0]
      kernel_weights = np.zeros(t)
      p = 1 / 10.0
      for i in range(1, t):
          kernel_weights[i] = ((1.0 - (i / t)) * ((1 - p) ** i)) + (
              (i / t) * ((1 - p) ** (t - i))
          )
      direct_vars = (demeaned**2).sum(0) / t
      for i in range(1, t):
          direct_vars += (
              2
              * kernel_weights[i]
              * (demeaned[: t - i, :] * demeaned[i:, :]).sum(0)
              / t
          )
      assert_allclose(direct_vars, variances)
  
      selection_criteria = -1.0 * np.sqrt(
          (direct_vars / t) * 2 * np.log(np.log(t))
      )
      valid = loss_diffs.mean(0) >= selection_criteria
      assert_equal(valid, spa._valid_columns)
  
      # Bootstrap variances
      spa = SPA(
          spa_data.benchmark,
          spa_data.models,
          block_size=10,
          reps=100,
          nested=True,
          seed=23456,
      )
      spa.compute()
      spa.reset()
      bs = spa.bootstrap.clone(demeaned, seed=23456)
      variances = spa._loss_diff_var
      bootstrap_variances = t * bs.var(
          lambda x: x.mean(0), reps=100, recenter=True
      )
      assert_allclose(bootstrap_variances, variances)
  
imports: from typing import NamedTuple
  import numpy
  from numpy import linspace
  from numpy.random import RandomState
  from numpy.testing import assert_allclose, assert_equal
  import pandas
  from pandas.testing import assert_frame_equal, assert_series_equal
  import pytest
  import scipy.stats
  from arch.bootstrap import CircularBlockBootstrap, MovingBlockBootstrap, StationaryBootstrap
  from arch.bootstrap.multiple_comparison import MCS, SPA, StepM
label_desc: Use image node_id 3 for calling a global function with example usage: test_variances_and_selection(spa_data) without return types