def test_dfgls_c(self): dfgls = DFGLS(self.inflation, trend="c", lags=0) assert_almost_equal(dfgls.stat, -6.017304, DECIMAL_4) dfgls.summary() dfgls.regression.summary() assert dfgls.trend == "c" with pytest.warns(FutureWarning, match="Mutating unit root"): dfgls.trend = "ct" assert dfgls.trend == "ct" with pytest.warns(FutureWarning, match="Mutating unit root"): dfgls.trend = "c" assert dfgls.trend == "c"
def DickeyFullerGlsTest(data, printResults=True, trend=None, lags=None): options_Trend = trend if trend != None else {'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} #options_LagMethod = lagMethod if lagMethod != None else {'AIC', 'BIC', 't-stat', None} results = dict() for column in data.columns: print("Dickey Fuller GLS test for column: " + column) results_Trend = dict() for option_Trend in options_Trend: results_Lag = dict() for option_Lag in options_Lags: result = DFGLS(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
def test_dfgls_c(self): dfgls = DFGLS(self.inflation, trend="c", lags=0) assert_almost_equal(dfgls.stat, -6.017304, DECIMAL_4) dfgls.summary() dfgls.regression.summary() assert dfgls.trend == "c" with pytest.warns(FutureWarning, match="Mutating unit root"): dfgls.trend = "c" assert dfgls.trend == "c" with pytest.warns(FutureWarning, match="Mutating unit root"): dfgls.trend = "ct" assert dfgls.trend == "ct" with pytest.warns(FutureWarning, match="Mutating unit root"): dfgls.trend = "c" assert dfgls.trend == "c" dfgls_hm = DFGLS(self.inflation, trend="c", lags=0, low_memory=False) assert_almost_equal(dfgls_hm.stat, -6.017304, DECIMAL_4) dfgls_lm = DFGLS(self.inflation, trend="c", lags=0, low_memory=True) assert_almost_equal(dfgls_lm.stat, -6.017304, DECIMAL_4) ml = dfgls.max_lags with pytest.warns(FutureWarning, match="Mutating unit root"): dfgls.max_lags = ml
def test_dfgls(self): dfgls = DFGLS(self.inflation, trend='ct', lags=0) assert_almost_equal(dfgls.stat, -6.300927, DECIMAL_4) dfgls.summary() dfgls.regression.summary()
""" #needs to have as input the prices or the residuals or the difference of the logs of the prices (i.e. log returns) #arch: DFGLS: if statistic is less than critical value reject null_H=rw from arch.unitroot import DFGLS arr = np.array(df1['spread'].values) dfgls = DFGLS( arr[-30:] ) #105 is the least data needed to calculate simple regression beta; 58 is the mninimum for overall accuracy of the model dfgls.trend = 'ct' #Constant and Linear Time Trend #dfgls.trend = 'c' #Constant trend print( 'If the dfgls test statistic is less than the critical value and pvalue=near zero, the series is mean reverting:' ) print(dfgls.summary().as_text()) #needs to have as input the log returns of the prices or the difference of the residuals #or difference of the log (p) -log (p.shift(1)) from vratio_hu import LoMac df1["spread_DIFF"] = df1["spread"] - df1["spread"].shift(1) df1 = df1.dropna() arr = np.array(df1["spread_DIFF"][-300:].values) l_k = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] arr_k = np.array(l_k) print( "If series is a rw, VR = 1, M1 = N(0,1) for iid series, M2 = N(0,1) for non iid series i.e. M1 = 0, M2 = 0" ) print( "If VR != 1, e.g. .4 (<1) and abs(M1) or abs(M2) greater than 1.96 for 2-tailed @ 95% cert, series is probably mean reverting"
def test_dfgls_c(self): dfgls = DFGLS(self.inflation, trend="c", lags=0) assert_almost_equal(dfgls.stat, -6.017304, DECIMAL_4) dfgls.summary() dfgls.regression.summary()