def ZivotAndrewsTest(data, printResults=True, trend=None, lags=None):
    options_Trend = trend if trend != None else {'c','t','ct'} #{'nc','c','ct','ctt'}
    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}
    #options_LagMethod = lagMethod if lagMethod != None else {'AIC', 'BIC', 't-stat', None}

    results = dict()
    for column in data.columns:
        print("Zivot Andrews test for column: " + column)
        results_Trend = dict()
        for option_Trend in options_Trend:
            results_Lag = dict()
            for option_Lag in options_Lags:
                result = ZivotAndrews(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
Пример #2
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
print(res.summary())