code: def dfgsl_simulation(
      n: int,
      trend: Literal["c", "ct"],
      b: int,
      rng: RandomState | None = None,
  ) -> float:
      """
      Simulates the empirical distribution of the DFGLS test statistic
      """
      if rng is None:
          rng = RandomState(0)
      standard_normal = rng.standard_normal
  
      nobs = n
      if trend == "c":
          c = -7.0
          z = np.ones((nobs, 1))
      else:
          c = -13.5
          z = np.vstack((np.ones(nobs), np.arange(1, nobs + 1))).T
  
      ct = c / nobs
  
      delta_z = np.copy(z)
      delta_z[1:, :] = delta_z[1:, :] - (1 + ct) * delta_z[:-1, :]
      delta_z_inv = pinv(delta_z)
      y = standard_normal((n + 50, b))
      y = np.cumsum(y, axis=0)
      y = y[50:, :]
      delta_y = y.copy()
      delta_y[1:, :] = delta_y[1:, :] - (1 + ct) * delta_y[:-1, :]
      detrend_coef = delta_z_inv.dot(delta_y)
      y_detrended = y - cast(np.ndarray, z.dot(detrend_coef))
  
      delta_y_detrended = np.diff(y_detrended, axis=0)
      rhs = y_detrended[:-1, :]
      lhs = delta_y_detrended
  
      xpy = np.sum(rhs * lhs, 0)
      xpx = np.sum(rhs**2.0, 0)
      gamma = xpy / xpx
      e = lhs - rhs * gamma
      sigma2 = np.sum(e**2.0, axis=0) / (n - 1)  # DOF correction?
      gamma_var = sigma2 / xpx
  
      stat = gamma / np.sqrt(gamma_var)
      return stat
  
file_path: arch/arch/unitroot/critical_values/simulation/dfgls_critical_values_simulation.py
imports: from __future__ import annotations
  import datetime
  from typing import cast
  import numpy
  from numpy.linalg import pinv
  from numpy.random import RandomState
  from statsmodels.tools.parallel import parallel_func
  from arch.typing import Literal
label_desc: Use image node_id 2 for calling a global function with example usage: dfgsl_simulation(n, trend, b, rng) and returns: stat