Exemple #1
0
def test_zivot_andrews(series_name):
    # Test results from package urca.ur.za (1.13-0)
    y = ZIVOT_ANDREWS_DATA[series_name].dropna()
    result = series[series_name]
    za = ZivotAndrews(y, lags=result.lags, trend=result.trend, max_lags=result.max_lags,
                      method=result.method)
    assert_almost_equal(za.stat, result.stat, decimal=3)
    assert_almost_equal(za.pvalue, result.pvalue, decimal=3)
    assert_equal(za.lags, result.actual_lags)
    assert isinstance(za.__repr__(), str)
Exemple #2
0
def test_zivot_andrews(series_name):
    # Test results from package urca.ur.za (1.13-0)
    y = ZIVOT_ANDREWS_DATA[series_name].dropna()
    result = series[series_name]
    za = ZivotAndrews(y,
                      lags=result.lags,
                      trend=result.trend,
                      max_lags=result.max_lags,
                      method=result.method)
    assert_almost_equal(za.stat, result.stat, decimal=3)
    assert_almost_equal(za.pvalue, result.pvalue, decimal=3)
    assert_equal(za.lags, result.actual_lags)
    assert isinstance(za.__repr__(), str)
Exemple #3
0
def test_wrong_exceptions_nearly_constant_series_za_lags(nobs, trend):
    y = np.zeros((nobs, ))
    y[-1] = 1.0
    try:
        assert np.isfinite(ZivotAndrews(y, lags=2, trend=trend).stat)
    except InfeasibleTestException:
        pass
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
Exemple #5
0
def test_zivot_andrews_reduced_rank():
    y = np.random.standard_normal(1000)
    y[1:] = 3.0
    with pytest.raises(InfeasibleTestException,
                       match="The regressor matrix is"):
        assert np.isfinite(ZivotAndrews(y, lags=1).stat)
Exemple #6
0
def test_zivot_andrews_error():
    series_name = "REAL_GNP"
    y = ZIVOT_ANDREWS_DATA[series_name].dropna()
    with pytest.raises(ValueError):
        ZivotAndrews(y, trim=0.5)
Exemple #7
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())
                        'CME Lean Hogs Future Return'
                    ])
#plt.savefig(files.image_path + '\LH_close_vol_return.png')

data = lh['Close'].resample('M').mean()  # resample daily data to monthly data
data = data['1992':'2004']
data = np.log(data / data.shift(1)).dropna() * 100  # d 1
adf = ADF(data)
print(adf.summary().as_text())
kpss = KPSS(data)
print(kpss.summary().as_text())
dfgls = DFGLS(data)
print(dfgls.summary().as_text())
pp = PhillipsPerron(data)
print(pp.summary().as_text())
za = ZivotAndrews(data)
print(za.summary().as_text())
vr = VarianceRatio(data, 12)
print(vr.summary().as_text())

print(data.describe())
print('Lean Hogs Future skewness is {}'.format(data.skew(axis=0)))
print('Lean Hogs Future kurtosis is {}'.format(data.kurtosis(axis=0)))

import matplotlib.gridspec as gridspec
import statsmodels.api as sm
import scipy.stats as stats
import seaborn as sns

# Plot figure with subplots of different sizes
fig = plt.figure(1)