code: def garch_sigma2(x0, x, p, q):
      w = x0[0]
      alpha = x0[1 : (p + 1)]
      beta = x0[(p + 1) :]
  
      sigma2 = np.full((len(x),), np.nan)
      sigma2[0] = np.var(
          x
      )  # sigma2 can be initialized with the unconditional variance
  
      for k in range(max(p, q), len(x)):
          psum = np.flip(alpha) * (x[k - p : k] ** 2)
          psum = np.nansum(psum)
          if q != 0:
              qsum = np.flip(beta) * (sigma2[k - q : k])
              qsum = np.nansum(qsum)
              sigma2[k] = w + psum + qsum
          else:
              sigma2[k] = w + psum
  
      return sigma2
  
file_path: statsforecast/statsforecast/garch.py
imports: import numpy
  from numba import njit
  from scipy.optimize import minimize
  from .utils import CACHE, NOGIL
label_desc: Use image node_id 2 for calling a global function with example usage: garch_sigma2(x0, x, p, q) and returns: sigma2