Skip to content

Commit

Permalink
Merge d1ef49d into 473431c
Browse files Browse the repository at this point in the history
  • Loading branch information
bashtage committed Mar 2, 2020
2 parents 473431c + d1ef49d commit 398bb94
Show file tree
Hide file tree
Showing 4 changed files with 624 additions and 56 deletions.
53 changes: 53 additions & 0 deletions arch/tests/univariate/test_rescale.py
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)
2 changes: 1 addition & 1 deletion arch/univariate/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def starting_values(self, std_resid: ArrayLike1D) -> NDArray:
def _simulator(self, size: Union[int, Tuple[int, ...]]) -> NDArray:
# No need to normalize since it is already done in parameterization
assert self._parameters is not None
return self.ppf(stats.uniform.rvs(size=size), self._parameters)
return self.ppf(self._random_state.random_sample(size=size), self._parameters)

def simulate(
self, parameters: Union[int, float, Sequence[Union[float, int]], ArrayLike1D]
Expand Down
3 changes: 3 additions & 0 deletions doc/source/changes/4.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Since 4.12
==========
- Issue warnings when unit root tests are mutated. Will raise after 5.0
is released.
- Fixed a bug in :class:`arch.univariate.SkewStudent` which did not use the
user-provided `RandomState` when one was provided. This prevented
reproducing simulated values (:issue:``).

Release 4.12
============
Expand Down
622 changes: 567 additions & 55 deletions examples/univariate_volatility_modeling.ipynb

Large diffs are not rendered by default.

0 comments on commit 398bb94

Please sign in to comment.