code: def test_har_forecast(self):
      am = arch_model(
          self.har3, mean="HAR", vol="Constant", lags=[1, 5, 22]
      )
      res = am.fit()
      fcast_1 = res.forecast(horizon=1)
      fcast_5 = res.forecast(horizon=5)
      assert_allclose(fcast_1.mean, fcast_5.mean.iloc[:, :1])
  
      with pytest.raises(ValueError):
          res.forecast(horizon=1, start=0)
      with pytest.raises(ValueError):
          res.forecast(horizon=1, start=20)
  
      fcast_66 = res.forecast(horizon=66, start=21)
      expected = np.empty((1000, 66 + 22))
      expected.fill(np.nan)
      for i in range(22):
          if i < 21:
              expected[21:, i] = self.har3.iloc[i : (-21 + i)]
          else:
              expected[21:, i] = self.har3.iloc[i:]
      params = np.asarray(res.params)
      const = params[0]
      arp = np.zeros(22)
      arp[0] = params[1]
      arp[:5] += params[2] / 5
      arp[:22] += params[3] / 22
      arp_rev = arp[::-1]
      for i in range(22, 88):
          expected[:, i] = const + expected[:, i - 22 : i].dot(arp_rev)
      expected = expected[:, 22:]
      assert_allclose(fcast_66.mean, expected[21:])
  
      expected[:22] = np.nan
      expected[22:] = res.params.iloc[-1]
      assert_allclose(fcast_66.residual_variance, expected[21:])
  
      impulse = _ar_to_impulse(66, arp)
      expected = expected * np.cumsum(impulse**2)
      assert_allclose(fcast_66.variance, expected[21:])
  
imports: import datetime
  from itertools import product
  import numpy
  from numpy.random import RandomState
  from numpy.testing import assert_allclose
  import pandas
  from pandas.testing import assert_frame_equal
  import pytest
  from arch.data import sp500
  from arch.tests.univariate.test_variance_forecasting import preserved_state
  from arch.univariate import APARCH, ARX, EGARCH, FIGARCH, GARCH, HARCH, HARX, ConstantMean, ConstantVariance, EWMAVariance, MIDASHyperbolic, RiskMetrics2006, ZeroMean, arch_model
  from arch.univariate.mean import _ar_forecast, _ar_to_impulse
label_desc: Use image node_id 9 for calling the TestForecasting obj's underlying member method code with example usage: obj.test_har_forecast() without return types