code: def test_arch_1_forecast_bootstrap(self):
      vol = GARCH(p=1, o=0, q=0)
      params = np.array([10.0, 0.4])
      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=5,
              method="bootstrap",
              random_state=self.rng,
          )
      sigma2 = np.zeros(1000)
      sigma2[0] = params[0] + params[1] * backcast
      for i in range(1, 1000):
          sigma2[i] = params[0] + params[1] * self.resid[i - 1] ** 2.0
      std_resids = self.resid / np.sqrt(sigma2)
      locs = np.floor(1000 * self.rng.random_sample((1000, 5))).astype(
          np.int64
      )
      std_shocks = std_resids[locs]
  
      paths = np.zeros((1000, 5))
      paths[:, 0] = params[0] + params[1] * self.resid[-1] ** 2.0
      shocks = np.zeros((1000, 5))
      shocks[:, 0] = np.sqrt(paths[:, 0]) * std_shocks[:, 0]
      for i in range(1, 5):
          paths[:, i] = params[0] + params[1] * shocks[:, i - 1] ** 2
          shocks[:, i] = np.sqrt(paths[:, i]) * std_shocks[:, i]
  
      assert forecast.forecasts.shape == (1, 5)
      assert forecast.forecast_paths.shape == (1, 1000, 5)
      assert forecast.shocks.shape == (1, 1000, 5)
      assert np.all(np.isfinite(forecast.forecasts))
      assert np.all(np.isfinite(forecast.forecast_paths))
      assert np.all(np.isfinite(forecast.shocks))
      assert_allclose(forecast.forecasts[-1], paths.mean(0))
      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=5,
              method="bootstrap",
              start=333,
              simulations=2000,
              random_state=self.rng,
          )
  
      paths = np.zeros((1000, 2000, 5))
      paths.fill(np.nan)
      shocks = np.zeros((1000, 2000, 5))
      shocks.fill(np.nan)
      for i in range(333, 1000):
          locs = self.rng.random_sample((2000, 5))
          int_locs = np.floor((i + 1) * locs).astype(np.int64)
          std_shocks = std_resids[int_locs]
          paths[i, :, 0] = params[0] + params[1] * self.resid[i] ** 2.0
          shocks[i, :, 0] = np.sqrt(paths[i, :, 0]) * std_shocks[:, 0]
          for j in range(1, 5):
              paths[i, :, j] = (
                  params[0] + params[1] * shocks[i, :, j - 1] ** 2
              )
              shocks[i, :, j] = (
                  np.sqrt(paths[i, :, j]) * std_shocks[:, j]
              )
  
      assert_allclose(forecast.forecast_paths, paths[333:])
      assert_allclose(forecast.forecasts, paths[333:].mean(1))
      assert_allclose(forecast.shocks, shocks[333:])
  
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 5 for calling the TestVarianceForecasts obj's underlying member method code with example usage: obj.test_arch_1_forecast_bootstrap() without return types