def ar_periodogram(x, window='hanning', window_len=7):
 (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)

def ar_periodogram ( x , window = 'hanning' , window_len = 7 ) : ( 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 )
compute periodogram from data x .