code: def simulate_kpss(
      nobs: int,
      b: int,
      trend: str = "c",
      rng: Optional[RandomState] = None,
  ) -> float:
      """
      Simulated the KPSS test statistic for nobs observations,
      performing b replications.
      """
      if rng is None:
          rng = RandomState()
          rng.seed(0)
  
      standard_normal = rng.standard_normal
  
      e = standard_normal((nobs, b))
      z = np.ones((nobs, 1))
      if trend == "ct":
          z = add_trend(z, trend="t")
      zinv = np.linalg.pinv(z)
      trend_coef = zinv.dot(e)
      resid = e - cast(np.ndarray, z.dot(trend_coef))
      s = np.cumsum(resid, axis=0)
      lam = (resid**2.0).mean(axis=0)
      kpss = 1 / (nobs**2.0) * (s**2.0).sum(axis=0) / lam
      return kpss
  
file_path: arch/arch/unitroot/critical_values/simulation/kpss_critical_values_simulation.py
imports: import os
  from typing import Optional, cast
  import numpy
  from numpy.random import RandomState
  import pandas
  from arch.utility.timeseries import add_trend
label_desc: Use image node_id 1 for calling a global function with example usage: simulate_kpss(nobs, b, trend, rng) and returns: kpss