def test_pp(self): pp = PhillipsPerron(self.inflation, lags=12) assert_almost_equal(pp.stat, -7.8076512, DECIMAL_4) assert pp.test_type == 'tau' pp.test_type = 'rho' assert_almost_equal(pp.stat, -108.1552688, DECIMAL_2) pp.summary()
def unitroot_test(series): # Basic statistic plt.figure() plt.plot(series) plot_pacf(series) # ADF test # AIC & BIC from lags 12 to 1 print('$p$ & AIC & BIC \\\\') max_lags = 12 for lags in (max_lags - i for i in range(max_lags)): ar_model = AutoReg(series, lags, 'n') res = ar_model.fit() print(f'{lags} & {round(res.aic, 3)} & {round(res.bic, 3)} \\\\') # Best lags by `ar_select_order` sel = ar_select_order(series, max_lags, trend='n') lags = sel.ar_lags[-1] print(f'Lags selection: {sel.ar_lags}') # Start ADF test adf = ADF(series, lags) print(adf.summary()) # PP test pp_tau = PhillipsPerron(series, 3, test_type='tau') # q = 3 pp_rho = PhillipsPerron(series, 3, test_type='rho') # q = 3 print(pp_tau.summary()) print(pp_rho.summary())
def test_pp(self): pp = PhillipsPerron(self.inflation, lags=12) assert_almost_equal(pp.stat, -7.8076512, DECIMAL_4) assert pp.test_type == "tau" with pytest.warns(FutureWarning, match="Mutating unit root"): pp.test_type = "rho" assert_almost_equal(pp.stat, -108.1552688, DECIMAL_2) pp.summary()
def PhilipsPerronTest(data, printResults=True, trend=None, lags=None): options_Trend = trend if trend != None else {'nc','c','ct'} options_Lags = lags if lags != None else {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24} results = dict() for column in data.columns: print("Philips Perron test for column: " + column) results_Trend = dict() for option_Trend in options_Trend: results_Lag = dict() for option_Lag in options_Lags: result = PhillipsPerron(data[column].dropna(), trend=option_Trend, lags=option_Lag) if printResults: result.summary() results_Lag[option_Lag] = result results_Trend[option_Trend] = results_Lag results[column] = results_Trend return results
print('Lean Hogs Future kurtosis is {}'.format(lh.kurtosis(axis=0)[0])) sns.distplot(lh['Close'], color='blue') #density plot plt.title('1986–2018 Lean Hogs Future return frequency') plt.xlabel('Possible range of data values') # Pull up summary statistics print(lh.describe()) adf = ADF(lh['Close']) print(adf.summary().as_text()) kpss = KPSS(lh['Close']) print(kpss.summary().as_text()) dfgls = DFGLS(lh['Close']) print(dfgls.summary().as_text()) pp = PhillipsPerron(lh['Close']) print(pp.summary().as_text()) za = ZivotAndrews(lh['Close']) print(za.summary().as_text()) vr = VarianceRatio(lh['Close'], 12) print(vr.summary().as_text()) from arch import arch_model X = 100 * lh import datetime as dt am = arch_model(X, p=4, o=0, q=0, vol='Garch', dist='StudentsT') res = am.fit(last_obs=dt.datetime(2003, 12, 31)) forecasts = res.forecast(horizon=1, start='2004-1-1') cond_mean = forecasts.mean['2004':] cond_var = forecasts.variance['2004':] / 31
def get_phillips_perron(timeseries): from arch.unitroot import PhillipsPerron pp = PhillipsPerron(timeseries) print(pp.summary().as_text())