-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
624 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import numpy as np | ||
from numpy.testing import assert_allclose | ||
import pandas as pd | ||
import pytest | ||
|
||
from arch.univariate import GARCH, Normal, ZeroMean | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def small_data(): | ||
rs = np.random.RandomState([2389280, 238901, 382908031]) | ||
mod = ZeroMean(None, volatility=GARCH(), distribution=Normal(random_state=rs)) | ||
sim = mod.simulate([1e-4, 0.05, 0.90], nobs=1000) | ||
return sim.data | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def small_data2(): | ||
rs = np.random.RandomState([2389280, 238901, 382908031]) | ||
mod = ZeroMean(None, volatility=GARCH(), distribution=Normal(random_state=rs)) | ||
sim = mod.simulate([1e-4, 0.05, 0.90], nobs=1000) | ||
return sim.data | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def std_data(): | ||
rs = np.random.RandomState([2389280, 238901, 382908031]) | ||
mod = ZeroMean(None, volatility=GARCH(), distribution=Normal(random_state=rs)) | ||
sim = mod.simulate([1e-1, 0.05, 0.90], nobs=1000) | ||
return sim.data | ||
|
||
|
||
def test_reproducibility(small_data, small_data2): | ||
pd.testing.assert_series_equal(small_data, small_data2) | ||
|
||
|
||
def test_blank(small_data, std_data): | ||
small_mod = ZeroMean(small_data, volatility=GARCH(), rescale=False) | ||
small_res = small_mod.fit(disp="off") | ||
mod = ZeroMean(std_data, volatility=GARCH(), rescale=False) | ||
res = mod.fit(disp="off") | ||
assert_allclose(1e3 * small_res.params[0], res.params[0], rtol=5e-3) | ||
|
||
|
||
def test_rescale_fit(small_data, std_data): | ||
small_mod = ZeroMean(small_data, volatility=GARCH(), rescale=True) | ||
small_res = small_mod.fit(disp="off") | ||
direct_mod = ZeroMean(10 * small_data, volatility=GARCH()) | ||
direct_res = direct_mod.fit(disp="off") | ||
assert_allclose(small_res.loglikelihood, direct_res.loglikelihood) | ||
small_fcast = small_res.forecast(start=0) | ||
direct_fcast = direct_res.forecast(start=0) | ||
assert_allclose(small_fcast.variance, direct_fcast.variance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.