code: def test_x_forecasting(nexog):
      rng = RandomState(12345)
      mod = arch_model(None, mean="ARX", lags=2)
      data = mod.simulate([0.1, 1.2, -0.6, 0.1, 0.1, 0.8], nobs=1000)
      cols = [f"x{i}" for i in range(1, nexog + 1)]
      x = pd.DataFrame(
          rng.standard_normal((data.data.shape[0], nexog)),
          columns=cols,
          index=data.data.index,
      )
      b = np.array([0.25, 0.5]) if x.shape[1] == 2 else np.array([0.25])
      y = data.data + x @ b
      y.name = "y"
      mod = arch_model(y, x, mean="ARX", lags=2)
      res = mod.fit(disp="off")
      x_fcast = np.zeros((x.shape[1], 1, 10))
      for i in range(x_fcast.shape[0]):
          x_fcast[i] = np.arange(100 * i, 100 * i + 10)
  
      forecasts = res.forecast(x=x_fcast, horizon=10)
      direct = np.zeros(12)
      direct[:2] = y.iloc[-2:]
      p0, p1, p2, *bs = res.params
      b0 = bs[0]
      b1 = bs[1] if x.shape[1] == 2 else 0.0
      for i in range(10):
          direct[i + 2] = p0 + p1 * direct[i + 1] + p2 * direct[i]
          direct[i + 2] += b0 * (i)
          direct[i + 2] += b1 * (100 + i)
      assert_allclose(forecasts.mean.iloc[0], direct[2:])
  
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 8 for calling a global function with example usage: test_x_forecasting(nexog) without return types