Пример #1
0
 def test_rgnpq_case(self):
     mdlfile = os.path.join(self.run_dir, 'rgnpq.csv')
     mdl = np.asarray(pd.read_csv(mdlfile))
     res = zivot_andrews(mdl, maxlag=12, regression='t', autolag='t-stat')
     assert_allclose([res[0], res[1], res[3], res[4]],
                     [-3.02761, 0.63993, 12, 102],
                     rtol=1e-3)
Пример #2
0
 def test_rand10000_case(self):
     mdlfile = os.path.join(self.run_dir, 'rand10000.csv')
     mdl = np.asarray(pd.read_csv(mdlfile))
     res = zivot_andrews(mdl, regression='c', autolag='t-stat')
     assert_allclose([res[0], res[1], res[3], res[4]],
                     [-3.48223, 0.69111, 25, 7071],
                     rtol=1e-3)
Пример #3
0
 def test_stkprc_case(self):
     mdlfile = os.path.join(self.run_dir, 'stkprc.csv')
     mdl = np.asarray(pd.read_csv(mdlfile))
     res = zivot_andrews(mdl, maxlag=8, regression='ct', autolag='t-stat')
     assert_allclose([res[0], res[1], res[3], res[4]],
                     [-5.60689, 0.00894, 1, 65],
                     rtol=1e-3)
Пример #4
0
 def test_gnpdef_case(self):
     mdlfile = os.path.join(self.run_dir, 'gnpdef.csv')
     mdl = np.asarray(pd.read_csv(mdlfile))
     res = zivot_andrews(mdl, maxlag=8, regression='c', autolag='t-stat')
     assert_allclose([res[0], res[1], res[3], res[4]],
                     [-4.12155, 0.28024, 5, 40],
                     rtol=1e-3)
Пример #5
0
 def test_rgnp_case(self):
     res = zivot_andrews(self.fail_mdl,
                         maxlag=8,
                         regression='c',
                         autolag=None)
     assert_allclose([res[0], res[1], res[4]], [-5.57615, 0.00312, 20],
                     rtol=1e-3)
Пример #6
0
    def check_stationarity(self, df):
        # Initializing flags.
        flag_news = False
        flag_tweets = False
        # Getting column list.
        col_list = df.columns.tolist()
        # Checking for tweets.
        result_tweets = zivot_andrews(df[col_list[0]])
        # Checking for news.
        result_news = adfuller(df[col_list[1]])

        # Displaying results.
        print("Result for news:")
        print("P-value: ", result_news[1])
        if (result_news[1] <= 0.05):
            flag_news = True
            print("Stationary: True")
        else:
            print("Stationary: False")
        print("Result for tweets:")
        print("P-value: ", result_tweets[1])
        if (result_tweets[1] <= 0.05):
            flag_tweets = True
            print("Stationary: True")
        else:
            print("Stationary: False")
        print("--------------------------------------")
        return flag_news, flag_tweets
Пример #7
0
def zivot_andrews_test(timeseries):
    print('Results of Zivot-Andrews Test:')
    zatest = zivot_andrews(timeseries, regression='ct', autolag='AIC')
    zaoutput = pd.Series(zatest[0:5],
                         index=[
                             'Test Statistic', 'p-value', 'Critical Values',
                             'Lags Used', 'Break Time'
                         ])
    print(zaoutput)
Пример #8
0
 def test_autolag_case_sensitivity(self, autolag):
     res = zivot_andrews(self.fail_mdl, autolag=autolag)
     assert res[3] == 1
Пример #9
0
 def test_fail_autolag_type(self):
     with pytest.raises(ValueError):
         zivot_andrews(self.fail_mdl, autolag='None')
Пример #10
0
 def test_fail_array_shape(self):
     with pytest.raises(ValueError):
         zivot_andrews(np.random.rand(50, 2))
Пример #11
0
 def test_fail_trim_value(self):
     with pytest.raises(ValueError):
         zivot_andrews(self.fail_mdl, trim=0.5)
Пример #12
0
 def test_fail_regression_type(self):
     with pytest.raises(ValueError):
         zivot_andrews(self.fail_mdl, regression='x')