Exemple #1
0
 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"
Exemple #2
0
 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
Exemple #3
0
    def test_dfgls_bad_trend(self):
        dfgls = DFGLS(self.inflation, trend='ct', method='BIC', max_lags=3)
        with pytest.raises(ValueError):
            dfgls.trend = 'nc'

        assert dfgls != 0.0
Exemple #4
0
    def test_dfgls_bad_trend(self):
        dfgls = DFGLS(self.inflation, trend="ct", method="BIC", max_lags=3)
        with pytest.raises(ValueError):
            dfgls.trend = "n"

        assert dfgls != 0.0
arr = np.array(df1['spread'].values)
halflife = halfLife_burak_mod.halflife(arr[-105:]) 
print ("Halflife = %f" %halflife)
#df['halflife'] = df.rolling(63).apply(lambda s: halfLife_burak_mod.halflife(s))
#df['halflife'].plot()

"""

#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)
Exemple #6
0
    def test_dfgls_bad_trend(self):
        dfgls = DFGLS(self.inflation, trend='ct', method='BIC', max_lags=3)
        with pytest.raises(ValueError):
            dfgls.trend = 'nc'

        assert dfgls != 0.0