Skip to content

Commit

Permalink
Merge pull request #222 from bashtage/low-memory-autolag
Browse files Browse the repository at this point in the history
ENH: Add low memory autolag method
  • Loading branch information
bashtage authored Aug 19, 2018
2 parents 4ac194c + 4de877f commit aefea99
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 55 deletions.
50 changes: 50 additions & 0 deletions arch/tests/unitroot/test_unitroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def test_adf_no_options(self):
assert_equal(adf.lags, 2)
assert_almost_equal(adf.pvalue, .027067, DECIMAL_4)
adf.regression.summary()
adf2 = ADF(self.inflation, low_memory=True)
assert_equal(adf2.lags, 2)

def test_adf_no_lags(self):
adf = ADF(self.inflation, lags=0).stat
Expand Down Expand Up @@ -68,6 +70,8 @@ def test_adf_lags_10(self):
def test_adf_auto_bic(self):
adf = ADF(self.inflation, method='BIC')
assert_equal(adf.lags, 2)
adf2 = ADF(self.inflation, method='BIC', low_memory=True)
assert_equal(adf2.lags, 2)

def test_adf_critical_value(self):
adf = ADF(self.inflation, trend='c', lags=3)
Expand All @@ -80,6 +84,8 @@ def test_adf_critical_value(self):
def test_adf_auto_t_stat(self):
adf = ADF(self.inflation, method='t-stat')
assert_equal(adf.lags, 11)
adf2 = ADF(self.inflation, method='t-stat', low_memory=True)
assert_equal(adf2.lags, 11)
old_stat = adf.stat
adf.lags += 1
assert adf.stat != old_stat
Expand Down Expand Up @@ -179,6 +185,9 @@ def test_variance_ratio(self):
ratio = num / denom

assert_almost_equal(ratio, vr.vr)
assert 'Variance-Ratio Test' in str(vr)
vr.debiased = True
assert vr.debiased is True

def test_variance_ratio_no_overlap(self):
vr = VarianceRatio(self.inflation, overlap=False)
Expand Down Expand Up @@ -342,3 +351,44 @@ def test_tstat_exogenous(self):
direct[i] = res.tvalues[-1]
crit = stats.norm.ppf(0.95)
assert np.max(np.argwhere(np.abs(direct[2:]) > crit)) == sel_lag


@pytest.mark.parametrize('trend', ['nc', 'c', 'ct', 'ctt'])
def test_trends_low_memory(trend):
rnd = np.random.RandomState(12345)
y = np.cumsum(rnd.randn(250))
adf = ADF(y, trend=trend, max_lags=16)
adf2 = ADF(y, trend=trend, low_memory=True, max_lags=16)
assert adf.lags == adf2.lags
assert adf.max_lags == 16


@pytest.mark.parametrize('trend', ['nc', 'c', 'ct', 'ctt'])
def test_representations(trend):
rnd = np.random.RandomState(12345)
y = np.cumsum(rnd.randn(250))
adf = ADF(y, trend=trend, max_lags=16)
check = 'Constant'
if trend == 'nc':
check = 'No Trend'
assert check in adf.__repr__()
assert check in adf.__repr__()
assert check in adf._repr_html_()
assert 'class="simpletable"' in adf._repr_html_()


def test_unknown_method():
rnd = np.random.RandomState(12345)
y = np.cumsum(rnd.randn(250))
with pytest.raises(ValueError):
ADF(y, method='unknown').stat


def test_auto_lowmemoty():
rnd = np.random.RandomState(12345)
y = np.cumsum(rnd.randn(250))
adf = ADF(y, trend='ct')
assert adf._low_memory is False
y = np.cumsum(rnd.randn(1000000))
adf = ADF(y, trend='ct')
assert adf._low_memory is True
Loading

0 comments on commit aefea99

Please sign in to comment.