code: def test_egarch(self):
      nobs = self.nobs
      parameters = np.array([0.0, 0.1, -0.1, 0.95])
      resids, sigma2 = self.resids, self.sigma2
      p = o = q = 1
      backcast = 0.0
      var_bounds = self.var_bounds
      lnsigma2 = np.empty_like(sigma2)
      std_resids = np.empty_like(sigma2)
      abs_std_resids = np.empty_like(sigma2)
      recpy.egarch_recursion(
          parameters,
          resids,
          sigma2,
          p,
          o,
          q,
          nobs,
          backcast,
          var_bounds,
          lnsigma2,
          std_resids,
          abs_std_resids,
      )
      sigma2_numba = sigma2.copy()
      recpy.egarch_recursion_python(
          parameters,
          resids,
          sigma2,
          p,
          o,
          q,
          nobs,
          backcast,
          var_bounds,
          lnsigma2,
          std_resids,
          abs_std_resids,
      )
      sigma2_python = sigma2.copy()
      rec.egarch_recursion(
          parameters,
          resids,
          sigma2,
          p,
          o,
          q,
          nobs,
          backcast,
          var_bounds,
          lnsigma2,
          std_resids,
          abs_std_resids,
      )
      assert_almost_equal(sigma2_numba, sigma2)
      assert_almost_equal(sigma2_python, sigma2)
  
      sigma2[:] = np.nan
      eu = recpy.EGARCHUpdater(p, o, q)
      eu.initialize_update(parameters, backcast, nobs)
      for t in range(nobs):
          eu._update_tester(
              t, parameters, resids, sigma2, self.var_bounds
          )
          if t == nobs // 2:
              eu = pickle.loads(pickle.dumps(eu))
      eu.initialize_update(parameters, backcast, nobs)
      assert_allclose(sigma2, sigma2_python)
  
      sigma2[:] = np.nan
      eu = rec.EGARCHUpdater(p, o, q)
      eu.initialize_update(parameters, backcast, nobs)
      for t in range(nobs):
          eu._update_tester(
              t, parameters, resids, sigma2, self.var_bounds
          )
          if t == nobs // 2:
              eu = pickle.loads(pickle.dumps(eu))
      eu.initialize_update(parameters, backcast, nobs)
      assert_allclose(sigma2, sigma2_python)
  
      norm_const = np.sqrt(2 / np.pi)
      for t in range(nobs):
          lnsigma2[t] = parameters[0]
          if t == 0:
              lnsigma2[t] += parameters[3] * backcast
          else:
              stdresid = resids[t - 1] / np.sqrt(sigma2[t - 1])
              lnsigma2[t] += parameters[1] * (
                  np.abs(stdresid) - norm_const
              )
              lnsigma2[t] += parameters[2] * stdresid
              lnsigma2[t] += parameters[3] * lnsigma2[t - 1]
          sigma2[t] = np.exp(lnsigma2[t])
      assert_almost_equal(sigma2_python, sigma2)
  
      parameters = np.array([-100.0, 0.1, -0.1, 0.95])
      recpy.egarch_recursion_python(
          parameters,
          resids,
          sigma2,
          p,
          o,
          q,
          nobs,
          backcast,
          var_bounds,
          lnsigma2,
          std_resids,
          abs_std_resids,
      )
      assert np.all(sigma2 >= self.var_bounds[:, 0])
      assert np.all(sigma2 <= 1.1 * self.var_bounds[:, 1])
  
      parameters = np.array([0.0, 0.1, -0.1, 9.5])
      recpy.egarch_recursion_python(
          parameters,
          resids,
          sigma2,
          p,
          o,
          q,
          nobs,
          backcast,
          var_bounds,
          lnsigma2,
          std_resids,
          abs_std_resids,
      )
      assert np.all(sigma2 >= self.var_bounds[:, 0])
      assert np.all(sigma2 <= 1.1 * self.var_bounds[:, 1])
  
      parameters = np.array([0.0, 0.1, -0.1, 0.95])
      mod_resids = resids.copy()
      mod_resids[:1] = np.inf
      recpy.egarch_recursion_python(
          parameters,
          resids,
          sigma2,
          p,
          o,
          q,
          nobs,
          backcast,
          var_bounds,
          lnsigma2,
          std_resids,
          abs_std_resids,
      )
      assert np.all(sigma2 >= self.var_bounds[:, 0])
      assert np.all(sigma2 <= 1.1 * self.var_bounds[:, 1])
  
      parameters = np.array([0.0, 31, -0.1, 0.95])
      mod_resids = resids.copy()
      mod_resids[100] = np.finfo(float).max
      recpy.egarch_recursion_python(
          parameters,
          mod_resids,
          sigma2,
          p,
          o,
          q,
          nobs,
          backcast,
          var_bounds,
          lnsigma2,
          std_resids,
          abs_std_resids,
      )
      assert np.all(sigma2 >= self.var_bounds[:, 0])
      assert np.all(sigma2 <= 1.1 * self.var_bounds[:, 1])
  
      rec.egarch_recursion(
          parameters,
          mod_resids,
          sigma2,
          p,
          o,
          q,
          nobs,
          backcast,
          var_bounds,
          lnsigma2,
          std_resids,
          abs_std_resids,
      )
      assert np.all(sigma2 >= self.var_bounds[:, 0])
      assert np.all(sigma2 <= 1.1 * self.var_bounds[:, 1])
  
imports: import os
  import pickle
  import timeit
  import types
  import numpy
  from numpy.random import RandomState
  from numpy.testing import assert_allclose, assert_almost_equal
  import pytest
  from scipy.special import gamma
  import arch.univariate.recursions_python
  from arch.univariate.volatility import RiskMetrics2006
label_desc: Use image node_id 14 for calling the TestRecursions obj's underlying member method code with example usage: obj.test_egarch() without return types