code: def test_garch11_simulation(self):
      t = self.t
      vol = GARCH(p=1, o=0, q=1)
      dist = Normal(seed=self.rng)
      rng = dist.simulate([])
      params = np.array([10.0, 0.1, 0.85])
      backcast = vol.backcast(self.resid)
      var_bounds = vol.variance_bounds(self.resid)
      with preserved_state(self.rng):
          forecast = vol.forecast(
              params,
              self.resid,
              backcast,
              var_bounds,
              horizon=10,
              method="simulation",
              rng=rng,
          )
      assert forecast.forecasts.shape == (1, 10)
      assert forecast.forecast_paths.shape == (1, 1000, 10)
      assert forecast.shocks.shape == (1, 1000, 10)
      assert np.all(np.isfinite(forecast.forecast_paths))
      assert np.all(np.isfinite(forecast.forecasts))
      assert np.all(np.isfinite(forecast.shocks))
      std_shocks = rng((1000, 10))
      one_step = vol.forecast(
          params, self.resid, backcast, var_bounds, horizon=1, start=0
      )
      paths = np.zeros((1000, 10))
      shocks = np.zeros((1000, 10))
      paths[:, 0] = one_step.forecasts[-1]
      shocks[:, 0] = np.sqrt(paths[:, 0]) * std_shocks[:, 0]
      for i in range(1, 10):
          paths[:, i] = params[0]
          paths[:, i] += params[1] * shocks[:, i - 1] ** 2.0
          paths[:, i] += params[2] * paths[:, i - 1]
          shocks[:, i] = np.sqrt(paths[:, i]) * std_shocks[:, i]
      forecasts = paths.mean(0)
      assert_allclose(forecast.forecasts[-1], forecasts)
      assert_allclose(forecast.forecast_paths[-1], paths)
      assert_allclose(forecast.shocks[-1], shocks)
  
      with preserved_state(self.rng):
          forecast = vol.forecast(
              params,
              self.resid,
              backcast,
              var_bounds,
              horizon=10,
              method="simulation",
              simulations=2000,
              rng=rng,
          )
      assert np.all(np.isfinite(forecast.forecast_paths))
      assert np.all(np.isfinite(forecast.forecasts))
      assert np.all(np.isfinite(forecast.shocks))
      assert forecast.forecasts.shape == (1, 10)
      assert forecast.forecast_paths.shape == (1, 2000, 10)
      assert forecast.shocks.shape == (1, 2000, 10)
      std_shocks = rng((2000, 10))
      paths = np.zeros((2000, 10))
      shocks = np.zeros((2000, 10))
      paths[:, 0] = one_step.forecasts[-1]
      shocks[:, 0] = np.sqrt(paths[:, 0]) * std_shocks[:, 0]
      for i in range(1, 10):
          paths[:, i] = params[0]
          paths[:, i] += params[1] * shocks[:, i - 1] ** 2.0
          paths[:, i] += params[2] * paths[:, i - 1]
          shocks[:, i] = np.sqrt(paths[:, i]) * std_shocks[:, i]
      forecasts = paths.mean(0)
      assert_allclose(forecast.forecasts[-1], forecasts)
      assert_allclose(forecast.forecast_paths[-1], paths)
      assert_allclose(forecast.shocks[-1], shocks)
  
      with preserved_state(self.rng):
          forecast = vol.forecast(
              params,
              self.resid,
              backcast,
              var_bounds,
              horizon=3,
              method="simulation",
              start=0,
              rng=rng,
          )
      paths = np.zeros((1000, 3))
      shocks = np.zeros((1000, 3))
      for j in range(t):
          std_shocks = rng((1000, 3))
          paths[:, 0] = one_step.forecasts[j]
          shocks[:, 0] = np.sqrt(paths[:, 0]) * std_shocks[:, 0]
          for i in range(1, 3):
              paths[:, i] = params[0]
              paths[:, i] += params[1] * shocks[:, i - 1] ** 2.0
              paths[:, i] += params[2] * paths[:, i - 1]
              shocks[:, i] = np.sqrt(paths[:, i]) * std_shocks[:, i]
          forecasts = paths.mean(0)
          assert_allclose(forecast.forecasts[j], forecasts)
          assert_allclose(forecast.forecast_paths[j], paths)
          assert_allclose(forecast.shocks[j], shocks)
  
imports: import numpy
  from numpy.random import RandomState
  from numpy.testing import assert_allclose
  import pandas
  import pytest
  from arch.univariate import arch_model
  from arch.univariate.distribution import Normal, StudentsT
  from arch.univariate.mean import ConstantMean
  from arch.univariate.volatility import APARCH, EGARCH, FIGARCH, GARCH, HARCH, BootstrapRng, ConstantVariance, EWMAVariance, FixedVariance, MIDASHyperbolic, RiskMetrics2006
label_desc: Use image node_id 24 for calling the TestVarianceForecasts obj's underlying member method code with example usage: obj.test_garch11_simulation() without return types