code: def test_harch(setup, initial_value):
      harch = HARCH(lags=[1, 5, 22])
  
      sv = harch.starting_values(setup.resids)
      assert_equal(sv.shape[0], harch.num_params)
  
      bounds = harch.bounds(setup.resids)
      assert_equal(
          bounds[0], (0.0, 10.0 * np.mean(setup.resids**2.0))
      )
      assert_equal(bounds[1], (0.0, 1.0))
      assert_equal(bounds[2], (0.0, 1.0))
      assert_equal(bounds[3], (0.0, 1.0))
      var_bounds = harch.variance_bounds(setup.resids)
      backcast = harch.backcast(setup.resids)
      w = 0.94 ** np.arange(75)
      assert_almost_equal(
          backcast, np.sum((setup.resids[:75] ** 2) * (w / w.sum()))
      )
  
      parameters = np.array([0.1, 0.4, 0.3, 0.2])
  
      var_bounds = harch.variance_bounds(setup.resids)
      harch.compute_variance(
          parameters, setup.resids, setup.sigma2, backcast, var_bounds
      )
      cond_var_direct = np.zeros_like(setup.sigma2)
      lags = np.array([1, 5, 22], dtype=np.int32)
      rec.harch_recursion(
          parameters,
          setup.resids,
          cond_var_direct,
          lags,
          setup.t,
          backcast,
          var_bounds,
      )
  
      names = harch.parameter_names()
      names_target = ["omega", "alpha[1]", "alpha[5]", "alpha[22]"]
      assert_equal(names, names_target)
  
      assert_allclose(setup.sigma2, cond_var_direct)
  
      a, b = harch.constraints()
      a_target = np.vstack(
          (np.eye(4), np.array([[0, -1.0, -1.0, -1.0]]))
      )
      b_target = np.array([0.0, 0.0, 0.0, 0.0, -1.0])
      assert_array_equal(a, a_target)
      assert_array_equal(b, b_target)
      state = setup.rng.get_state()
      rng = Normal(seed=RandomState())
      rng.generator.set_state(state)
      sim_data = harch.simulate(
          parameters,
          setup.t,
          rng.simulate([]),
          initial_value=initial_value,
      )
      setup.rng.set_state(state)
      e = setup.rng.standard_normal(setup.t + 500)
      sigma2 = np.zeros(setup.t + 500)
      data = np.zeros(setup.t + 500)
      lagged = np.zeros(22)
      for t in range(setup.t + 500):
          sigma2[t] = parameters[0]
          lagged[:] = backcast
          if t > 0:
              if t == 1:
                  lagged[0] = data[0] ** 2.0
              elif t < 22:
                  lagged[:t] = data[t - 1 :: -1] ** 2.0
              else:
                  lagged = data[t - 1 : t - 22 : -1] ** 2.0
  
          shock1 = data[t - 1] ** 2.0 if t > 0 else backcast
          if t >= 5:
              shock5 = np.mean(data[t - 5 : t] ** 2.0)
          else:
              shock5 = 0.0
              for i in range(5):
                  shock5 += (
                      data[t - i - 1] if t - i - 1 >= 0 else backcast
                  )
              shock5 = shock5 / 5.0
  
          if t >= 22:
              shock22 = np.mean(data[t - 22 : t] ** 2.0)
          else:
              shock22 = 0.0
              for i in range(22):
                  shock22 += (
                      data[t - i - 1] if t - i - 1 >= 0 else backcast
                  )
              shock22 = shock22 / 22.0
  
          sigma2[t] += (
              parameters[1] * shock1
              + parameters[2] * shock5
              + parameters[3] * shock22
          )
  
          data[t] = e[t] * np.sqrt(sigma2[t])
      data = data[500:]
      sigma2 = sigma2[500:]
      assert_almost_equal(data - sim_data[0] + 1.0, np.ones_like(data))
      assert_almost_equal(sigma2 / sim_data[1], np.ones_like(sigma2))
  
      assert_equal(harch.name, "HARCH")
      assert_equal(harch.lags, [1, 5, 22])
      assert_equal(harch.num_params, 4)
      assert isinstance(harch.__str__(), str)
      txt = harch.__repr__()
      assert str(hex(id(harch))) in txt
  
imports: import types
  from typing import NamedTuple
  import warnings
  import numpy
  from numpy.random import RandomState
  from numpy.testing import assert_allclose, assert_almost_equal, assert_array_equal, assert_equal
  import pytest
  from scipy.special import gamma, gammaln
  from arch.univariate import ZeroMean
  from arch.univariate.distribution import Normal, SkewStudent, StudentsT
  import arch.univariate.recursions_python
  from arch.univariate.volatility import APARCH, ARCH, EGARCH, FIGARCH, GARCH, HARCH, ConstantVariance, EWMAVariance, FixedVariance, MIDASHyperbolic, RiskMetrics2006
  from arch.utility.exceptions import InitialValueWarning
label_desc: Use image node_id 6 for calling a global function with example usage: test_harch(setup, initial_value) without return types