Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions arch/tests/univariate/test_volatility.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,25 @@ def test_harch(setup, initial_value):
assert str(hex(id(harch))) in txt


def test_harch_simulate_vector_initial_value():
harch = HARCH(lags=[1, 3])
params = np.array([0.1, 0.2, 0.3])
iv = np.array([1.0, 4.0, 9.0])
_, sigma2 = harch.simulate(
params,
5,
rng=np.zeros,
burn=0,
initial_value=iv,
)
assert_allclose(sigma2[:3], iv)
expected_lag1 = iv[2]
expected_lag3 = np.mean(iv)
assert_allclose(
sigma2[3], params[0] + params[1] * expected_lag1 + params[2] * expected_lag3
)


def test_constant_variance(setup):
cv = ConstantVariance()

Expand Down Expand Up @@ -1242,6 +1261,22 @@ def test_midas_symmetric(setup, initial_value):
midas.simulate(parameters, setup.t, rng.simulate([]))


def test_midas_simulate_vector_initial_value():
midas = MIDASHyperbolic(m=3)
params = np.array([0.1, 0.4, 0.5])
iv = np.array([1.0, 4.0, 9.0])
_, sigma2 = midas.simulate(
params,
5,
rng=np.zeros,
burn=0,
initial_value=iv,
)
weights = midas._weights(params)
expected_first = params[0] + params[1] * np.dot(weights, iv[::-1])
assert_allclose(sigma2[0], expected_first)


def test_midas_asymmetric(setup):
midas = MIDASHyperbolic(33, asym=True)

Expand Down
4 changes: 2 additions & 2 deletions arch/univariate/volatility.py
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,7 @@ def simulate(
data[:max_lag] = np.sqrt(initial_value)
# The squared data, to avoid squaring it once for each term of each sum
data2 = np.empty(nobs + burn)
data2[:max_lag] = data[0] ** 2.0
data2[:max_lag] = data[:max_lag] ** 2.0
# The weight and the lag of each term that is added to omega, in order.
# The terms are added one at a time, in this order, using a cumulative sum
weights = np.concatenate(
Expand Down Expand Up @@ -2460,7 +2460,7 @@ def simulate(
data[:m] = np.sqrt(initial_value)
# The squared data, to avoid squaring it once for each term of each sum
data2 = np.empty(nobs + burn)
data2[:m] = data[0] ** 2.0
data2[:m] = data[:m] ** 2.0
# Coefficient on the first m values, which are initial values
init_coef = aw + 0.5 * gw
# The m terms that are added to omega are added one at a time, in order of
Expand Down
Loading