From d2e8cb1fd4760373f688cc570b5f97652d13e536 Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Fri, 5 Jan 2024 12:40:15 +0000 Subject: [PATCH] MAINT: Make case less extreme --- arch/tests/univariate/test_volatility.py | 4 ++-- arch/univariate/volatility.py | 16 ++++++++++++++-- arch/utility/exceptions.py | 4 ++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/arch/tests/univariate/test_volatility.py b/arch/tests/univariate/test_volatility.py index b313652c42..2ddc61e77a 100644 --- a/arch/tests/univariate/test_volatility.py +++ b/arch/tests/univariate/test_volatility.py @@ -1431,9 +1431,9 @@ def test_figarch(setup, initial_value): assert_equal(figarch.num_params, 4) assert_equal(figarch.truncation, trunc_lag) - params = np.array([0.1, 0.2, 0.4, 1.1]) + params = np.array([0.1, 1.01, 0.4, 1.005]) with pytest.warns(InitialValueWarning): - figarch.simulate(params, 1000, rng.simulate([])) + figarch.simulate(params, 20, rng.simulate([])) def test_figarch_no_phi(setup): diff --git a/arch/univariate/volatility.py b/arch/univariate/volatility.py index 68a59b66ce..2738301bb5 100644 --- a/arch/univariate/volatility.py +++ b/arch/univariate/volatility.py @@ -25,7 +25,11 @@ ) from arch.univariate.distribution import Normal from arch.utility.array import AbstractDocStringInheritor, ensure1d -from arch.utility.exceptions import InitialValueWarning, initial_value_warning +from arch.utility.exceptions import ( + InitialValueWarning, + ValueWarning, + initial_value_warning, +) if TYPE_CHECKING: from arch.univariate import recursions_python as rec @@ -3143,7 +3147,15 @@ def simulate( fdata[:truncation] = abs(data[:truncation]) ** power omega = parameters[0] beta = parameters[-1] if q else 0 - omega_tilde = omega / (1 - beta) + if beta < 1: + omega_tilde = omega / (1 - beta) + else: + warn( + "beta >= 1.0, using omega as intercept since long-run variance " + "is ill-defined.", + ValueWarning, + ) + omega_tilde = omega for t in range(truncation, truncation + nobs + burn): fsigma[t] = omega_tilde + lam_rev.dot(fdata[t - truncation : t]) sigma2[t] = fsigma[t] ** (2.0 / power) diff --git a/arch/utility/exceptions.py b/arch/utility/exceptions.py index 3d10c04950..e279b970b1 100644 --- a/arch/utility/exceptions.py +++ b/arch/utility/exceptions.py @@ -88,3 +88,7 @@ class InfeasibleTestException(RuntimeError): class PerformanceWarning(UserWarning): """Warning issued if recursions are run in CPython""" + + +class ValueWarning(UserWarning): + """Warning issued if value is problematic but no fatal."""