

def ar_periodogram(x, window='hanning', window_len=7):
    "\n    Compute periodogram from data x, using prewhitening, smoothing and\n    recoloring.  The data is fitted to an AR(1) model for prewhitening,\n    and the residuals are used to compute a first-pass periodogram with\n    smoothing.  The fitted coefficients are then used for recoloring.\n\n    Parameters\n    ----------\n    x : array_like(float)\n        A flat NumPy array containing the data to smooth\n    window_len : scalar(int), optional\n        An odd integer giving the length of the window.  Defaults to 7.\n    window : string\n        A string giving the window type. Possible values are 'flat',\n        'hanning', 'hamming', 'bartlett' or 'blackman'\n\n    Returns\n    -------\n    w : array_like(float)\n        Fourier frequences at which periodogram is evaluated\n    I_w : array_like(float)\n        Values of periodogram at the Fourier frequences\n\n    "
    (x_current, x_lagged) = (x[1:], x[:(- 1)])
    (x_current, x_lagged) = (Series(x_current), Series(x_lagged))
    results = ols(y=x_current, x=x_lagged, intercept=True, nw_lags=1)
    e_hat = results.resid.values
    phi = results.beta['x']
    (w, I_w) = periodogram(e_hat, window=window, window_len=window_len)
    I_w = (I_w / (np.abs((1 - (phi * np.exp((1j * w))))) ** 2))
    return (w, I_w)

dataset/ETHPy150Open QuantEcon/QuantEcon.py/quantecon/estspec.py ar_periodogram/original