import os
import timeit
from typing import List

import numpy as np
from numpy.random import RandomState
from numpy.testing import assert_allclose, assert_almost_equal
import pytest
from scipy.special import gamma

import arch.univariate.recursions_python as recpy

CYTHON_COVERAGE = os.environ.get("ARCH_CYTHON_COVERAGE", "0") in ("true", "1", "True")

try:
    import arch.univariate.recursions as rec_cython

    missing_extension = False
except ImportError:
    missing_extension = True

if missing_extension:
    rec = recpy
else:
    rec = rec_cython

try:
    import numba  # noqa

    missing_numba = False
except ImportError:
    missing_numba = True

pytestmark = pytest.mark.filterwarnings("ignore::arch.compat.numba.PerformanceWarning")


class Timer(object):
    def __init__(
        self,
        first,
        first_name,
        second,
        second_name,
        model_name,
        setup,
        repeat=5,
        number=10,
    ) -> None:
        self.first_code = first
        self.second_code = second
        self.setup = setup
        self.first_name = first_name
        self.second_name = second_name
        self.model_name = model_name
        self.repeat = repeat
        self.number = number
        self._run = False
        self.times: List[float] = []
        self._codes = [first, second]
        self.ratio = np.inf

    def display(self):
        if not self._run:
            self.time()
        self.ratio = self.times[0] / self.times[1]
        title = self.model_name + " timing"
        print("\n" + title)
        print("-" * len(title))
        print(self.first_name + ": " + "{:0.3f} ms".format(1000 * self.times[0]))
        print(self.second_name + ": " + "{:0.3f} ms".format(1000 * self.times[1]))
        if self.ratio < 1:
            print(
                "{0} is {1:0.1f}% faster".format(
                    self.first_name, 100 * (1 / self.ratio - 1)
                )
            )
        else:
            print(
                "{0} is {1:0.1f}% faster".format(
                    self.second_name, 100 * (self.ratio - 1)
                )
            )
        print(
            self.first_name
            + "/"
            + self.second_name
            + " Ratio: {:0.3f}\n".format(self.ratio)
        )

    def time(self):
        self.times = []
        for code in self._codes:
            timer = timeit.Timer(code, setup=self.setup)
            self.times.append(min(timer.repeat(self.repeat, self.number)))


class TestRecursions(object):
    @classmethod
    def setup_class(cls):
        cls.nobs = 1000
        cls.rng = RandomState(12345)
        cls.resids = cls.rng.standard_normal(cls.nobs)
        cls.sigma2 = np.zeros_like(cls.resids)
        var = cls.resids.var()
        var_bounds = np.array([var / 1000000.0, var * 1000000.0])
        cls.var_bounds = np.ones((cls.nobs, 2)) * var_bounds
        cls.backcast = 1.0
        cls.timer_setup = """
import numpy as np
import arch.univariate.recursions as rec
import arch.univariate.recursions_python as recpy

nobs = 10000
resids = np.random.standard_normal(nobs)
sigma2 = np.zeros_like(resids)
var = resids.var()
backcast = 1.0
var_bounds = np.array([var / 1000000.0, var * 1000000.0])
var_bounds = np.ones((nobs, 2)) * var_bounds
"""

    def test_garch(self):
        nobs, resids = self.nobs, self.resids
        sigma2, backcast = self.sigma2, self.backcast

        parameters = np.array([0.1, 0.4, 0.3, 0.2])
        fresids = resids ** 2.0
        sresids = np.sign(resids)

        recpy.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        sigma2_numba = sigma2.copy()
        recpy.garch_recursion_python(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        sigma2_python = sigma2.copy()
        rec.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert_almost_equal(sigma2_numba, sigma2)
        assert_almost_equal(sigma2_python, sigma2)

        parameters = np.array([0.1, -0.4, 0.3, 0.2])
        recpy.garch_recursion_python(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([0.1, 0.4, 3, 2])
        recpy.garch_recursion_python(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([0.1, 0.4, 0.3, 0.2])
        mod_fresids = fresids.copy()
        mod_fresids[:1] = np.inf
        recpy.garch_recursion_python(
            parameters,
            mod_fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])
        rec.garch_recursion(
            parameters,
            mod_fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

    def test_harch(self):
        nobs, resids = self.nobs, self.resids
        sigma2, backcast = self.sigma2, self.backcast

        parameters = np.array([0.1, 0.4, 0.3, 0.2])
        lags = np.array([1, 5, 22], dtype=np.int32)
        recpy.harch_recursion_python(
            parameters, resids, sigma2, lags, nobs, backcast, self.var_bounds
        )
        sigma2_python = sigma2.copy()
        recpy.harch_recursion(
            parameters, resids, sigma2, lags, nobs, backcast, self.var_bounds
        )
        sigma2_numba = sigma2.copy()
        rec.harch_recursion(
            parameters, resids, sigma2, lags, nobs, backcast, self.var_bounds
        )
        assert_almost_equal(sigma2_numba, sigma2)
        assert_almost_equal(sigma2_python, sigma2)

        parameters = np.array([-0.1, -0.4, 0.3, 0.2])
        recpy.harch_recursion_python(
            parameters, resids, sigma2, lags, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([0.1, 4e8, 3, 2])
        recpy.harch_recursion_python(
            parameters, resids, sigma2, lags, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([0.1, 4e8, 3, 2])
        mod_resids = resids.copy()
        mod_resids[:10] = np.inf
        recpy.harch_recursion_python(
            parameters, mod_resids, sigma2, lags, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])
        rec.harch_recursion(
            parameters, mod_resids, sigma2, lags, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

    def test_arch(self):
        nobs, resids = self.nobs, self.resids
        sigma2, backcast = self.sigma2, self.backcast

        parameters = np.array([0.1, 0.4, 0.3, 0.2])
        p = 3

        recpy.arch_recursion_python(
            parameters, resids, sigma2, p, nobs, backcast, self.var_bounds
        )
        sigma2_python = sigma2.copy()
        recpy.arch_recursion(
            parameters, resids, sigma2, p, nobs, backcast, self.var_bounds
        )
        sigma2_numba = sigma2.copy()
        rec.arch_recursion(
            parameters, resids, sigma2, p, nobs, backcast, self.var_bounds
        )
        assert_almost_equal(sigma2_numba, sigma2)
        assert_almost_equal(sigma2_python, sigma2)

        parameters = np.array([-0.1, -0.4, 0.3, 0.2])
        recpy.arch_recursion_python(
            parameters, resids, sigma2, p, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([0.1, 4e8, 3, 2])
        recpy.arch_recursion_python(
            parameters, resids, sigma2, p, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        mod_resids = resids.copy()
        mod_resids[:10] = np.inf
        recpy.arch_recursion_python(
            parameters, mod_resids, sigma2, p, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])
        rec.arch_recursion(
            parameters, mod_resids, sigma2, p, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

    def test_garch_power_1(self):
        nobs, resids = self.nobs, self.resids
        sigma2, backcast = self.sigma2, self.backcast

        parameters = np.array([0.1, 0.4, 0.3, 0.2])
        fresids = np.abs(resids) ** 1.0
        sresids = np.sign(resids)

        recpy.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        sigma2_python = sigma2.copy()
        rec.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert_almost_equal(sigma2_python, sigma2)

    def test_garch_direct(self):
        nobs, resids = self.nobs, self.resids
        sigma2, backcast = self.sigma2, self.backcast

        parameters = np.array([0.1, 0.4, 0.3, 0.2])
        fresids = np.abs(resids) ** 2.0
        sresids = np.sign(resids)

        for t in range(nobs):
            if t == 0:
                sigma2[t] = parameters.dot(
                    np.array([1.0, backcast, 0.5 * backcast, backcast])
                )
            else:
                var = np.array(
                    [
                        1.0,
                        resids[t - 1] ** 2.0,
                        resids[t - 1] ** 2.0 * (resids[t - 1] < 0),
                        sigma2[t - 1],
                    ]
                )
                sigma2[t] = parameters.dot(var)

        sigma2_python = sigma2.copy()
        rec.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert_almost_equal(sigma2_python, sigma2)

    def test_garch_no_q(self):
        nobs, resids = self.nobs, self.resids
        sigma2, backcast = self.sigma2, self.backcast

        parameters = np.array([0.1, 0.4, 0.3])
        fresids = resids ** 2.0
        sresids = np.sign(resids)

        recpy.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            0,
            nobs,
            backcast,
            self.var_bounds,
        )
        sigma2_python = sigma2.copy()
        rec.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            0,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert_almost_equal(sigma2_python, sigma2)

    def test_garch_no_p(self):
        nobs, resids = self.nobs, self.resids
        sigma2, backcast = self.sigma2, self.backcast

        parameters = np.array([0.1, 0.4, 0.3])
        fresids = resids ** 2.0
        sresids = np.sign(resids)

        recpy.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            0,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        sigma2_python = sigma2.copy()
        rec.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            0,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert_almost_equal(sigma2_python, sigma2)

    def test_garch_no_o(self):
        nobs, resids = self.nobs, self.resids
        sigma2, backcast = self.sigma2, self.backcast

        parameters = np.array([0.1, 0.4, 0.3, 0.2])
        fresids = resids ** 2.0
        sresids = np.sign(resids)

        recpy.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            0,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        sigma2_python = sigma2.copy()
        rec.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            0,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert_almost_equal(sigma2_python, sigma2)

    def test_garch_arch(self):
        backcast = self.backcast
        nobs, resids, sigma2 = self.nobs, self.resids, self.sigma2

        parameters = np.array([0.1, 0.4, 0.3, 0.2])
        fresids = resids ** 2.0
        sresids = np.sign(resids)

        rec.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            3,
            0,
            0,
            nobs,
            backcast,
            self.var_bounds,
        )
        sigma2_garch = sigma2.copy()
        rec.arch_recursion(
            parameters, resids, sigma2, 3, nobs, backcast, self.var_bounds
        )

        assert_almost_equal(sigma2_garch, sigma2)

    def test_bounds(self):
        nobs, resids = self.nobs, self.resids
        sigma2, backcast = self.sigma2, self.backcast

        parameters = np.array([1e100, 0.4, 0.3, 0.2])
        lags = np.array([1, 5, 22], dtype=np.int32)
        recpy.harch_recursion(
            parameters, resids, sigma2, lags, nobs, backcast, self.var_bounds
        )
        sigma2_python = sigma2.copy()
        rec.harch_recursion(
            parameters, resids, sigma2, lags, nobs, backcast, self.var_bounds
        )
        assert_almost_equal(sigma2_python, sigma2)
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([-1e100, 0.4, 0.3, 0.2])
        recpy.harch_recursion(
            parameters, resids, sigma2, lags, nobs, backcast, self.var_bounds
        )
        sigma2_python = sigma2.copy()
        rec.harch_recursion(
            parameters, resids, sigma2, lags, nobs, backcast, self.var_bounds
        )
        assert_almost_equal(sigma2_python, sigma2)
        assert_almost_equal(sigma2, self.var_bounds[:, 0])

        parameters = np.array([1e100, 0.4, 0.3, 0.2])
        fresids = resids ** 2.0
        sresids = np.sign(resids)

        recpy.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        sigma2_python = sigma2.copy()
        rec.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert_almost_equal(sigma2_python, sigma2)
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([-1e100, 0.4, 0.3, 0.2])
        recpy.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        sigma2_python = sigma2.copy()
        rec.garch_recursion(
            parameters,
            fresids,
            sresids,
            sigma2,
            1,
            1,
            1,
            nobs,
            backcast,
            self.var_bounds,
        )
        assert_almost_equal(sigma2_python, sigma2)
        assert_almost_equal(sigma2, self.var_bounds[:, 0])

        parameters = np.array([1e100, 0.4, 0.3, 0.2])
        recpy.arch_recursion(
            parameters, resids, sigma2, 3, nobs, backcast, self.var_bounds
        )
        sigma2_python = sigma2.copy()
        rec.arch_recursion(
            parameters, resids, sigma2, 3, nobs, backcast, self.var_bounds
        )
        assert_almost_equal(sigma2_python, sigma2)
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([-1e100, 0.4, 0.3, 0.2])
        recpy.arch_recursion(
            parameters, resids, sigma2, 3, nobs, backcast, self.var_bounds
        )
        sigma2_python = sigma2.copy()
        rec.arch_recursion(
            parameters, resids, sigma2, 3, nobs, backcast, self.var_bounds
        )
        assert_almost_equal(sigma2_python, sigma2)
        assert_almost_equal(sigma2, self.var_bounds[:, 0])

    def test_egarch(self):
        nobs = self.nobs
        parameters = np.array([0.0, 0.1, -0.1, 0.95])
        resids, sigma2 = self.resids, self.sigma2
        p = o = q = 1
        backcast = 0.0
        var_bounds = self.var_bounds
        lnsigma2 = np.empty_like(sigma2)
        std_resids = np.empty_like(sigma2)
        abs_std_resids = np.empty_like(sigma2)
        recpy.egarch_recursion(
            parameters,
            resids,
            sigma2,
            p,
            o,
            q,
            nobs,
            backcast,
            var_bounds,
            lnsigma2,
            std_resids,
            abs_std_resids,
        )
        sigma2_numba = sigma2.copy()
        recpy.egarch_recursion_python(
            parameters,
            resids,
            sigma2,
            p,
            o,
            q,
            nobs,
            backcast,
            var_bounds,
            lnsigma2,
            std_resids,
            abs_std_resids,
        )
        sigma2_python = sigma2.copy()
        rec.egarch_recursion(
            parameters,
            resids,
            sigma2,
            p,
            o,
            q,
            nobs,
            backcast,
            var_bounds,
            lnsigma2,
            std_resids,
            abs_std_resids,
        )
        assert_almost_equal(sigma2_numba, sigma2)
        assert_almost_equal(sigma2_python, sigma2)

        norm_const = np.sqrt(2 / np.pi)
        for t in range(nobs):
            lnsigma2[t] = parameters[0]
            if t == 0:
                lnsigma2[t] += parameters[3] * backcast
            else:
                stdresid = resids[t - 1] / np.sqrt(sigma2[t - 1])
                lnsigma2[t] += parameters[1] * (np.abs(stdresid) - norm_const)
                lnsigma2[t] += parameters[2] * stdresid
                lnsigma2[t] += parameters[3] * lnsigma2[t - 1]
            sigma2[t] = np.exp(lnsigma2[t])
        assert_almost_equal(sigma2_python, sigma2)

        parameters = np.array([-100.0, 0.1, -0.1, 0.95])
        recpy.egarch_recursion_python(
            parameters,
            resids,
            sigma2,
            p,
            o,
            q,
            nobs,
            backcast,
            var_bounds,
            lnsigma2,
            std_resids,
            abs_std_resids,
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([0.0, 0.1, -0.1, 9.5])
        recpy.egarch_recursion_python(
            parameters,
            resids,
            sigma2,
            p,
            o,
            q,
            nobs,
            backcast,
            var_bounds,
            lnsigma2,
            std_resids,
            abs_std_resids,
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([0.0, 0.1, -0.1, 0.95])
        mod_resids = resids.copy()
        mod_resids[:1] = np.inf
        recpy.egarch_recursion_python(
            parameters,
            resids,
            sigma2,
            p,
            o,
            q,
            nobs,
            backcast,
            var_bounds,
            lnsigma2,
            std_resids,
            abs_std_resids,
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

    def test_midas_hyperbolic(self):
        nobs, resids = self.nobs, self.resids
        sigma2, backcast = self.sigma2, self.backcast

        parameters = np.array([0.1, 0.8, 0])
        j = np.arange(1, 22 + 1)
        weights = gamma(j + 0.6) / (gamma(j + 1) * gamma(0.6))
        weights = weights / weights.sum()
        recpy.midas_recursion(
            parameters, weights, resids, sigma2, nobs, backcast, self.var_bounds
        )
        sigma2_numba = sigma2.copy()
        recpy.midas_recursion_python(
            parameters, weights, resids, sigma2, nobs, backcast, self.var_bounds
        )
        sigma2_python = sigma2.copy()
        rec.midas_recursion(
            parameters, weights, resids, sigma2, nobs, backcast, self.var_bounds
        )
        assert_almost_equal(sigma2_numba, sigma2)
        assert_almost_equal(sigma2_python, sigma2)

        mod_resids = resids.copy()
        mod_resids[:10] = np.inf
        recpy.midas_recursion_python(
            parameters, weights, mod_resids, sigma2, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([0.1, 10e10, 0])
        j = np.arange(1, 22 + 1)
        weights = gamma(j + 0.6) / (gamma(j + 1) * gamma(0.6))
        weights = weights / weights.sum()
        recpy.midas_recursion_python(
            parameters, weights, resids, sigma2, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])
        rec.midas_recursion(
            parameters, weights, resids, sigma2, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

        parameters = np.array([0.1, -0.4, 0])
        recpy.midas_recursion_python(
            parameters, weights, resids, sigma2, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])
        rec.midas_recursion(
            parameters, weights, resids, sigma2, nobs, backcast, self.var_bounds
        )
        assert np.all(sigma2 >= self.var_bounds[:, 0])
        assert np.all(sigma2 <= 2 * self.var_bounds[:, 1])

    def test_figarch_recursion(self):
        nobs, resids = self.nobs, self.resids
        sigma2, backcast = self.sigma2, self.backcast
        parameters = np.array([1.0, 0.2, 0.4, 0.3])
        fresids = resids ** 2
        p = q = 1
        trunc_lag = 1000
        rec.figarch_recursion(
            parameters,
            fresids,
            sigma2,
            p,
            q,
            nobs,
            trunc_lag,
            backcast,
            self.var_bounds,
        )
        lam = rec.figarch_weights(parameters[1:], p, q, trunc_lag=trunc_lag)
        lam_rev = lam[::-1]
        omega_tilde = parameters[0] / (1 - parameters[-1])
        sigma2_direct = np.empty_like(sigma2)
        for t in range(nobs):
            backcasts = trunc_lag - t
            sigma2_direct[t] = omega_tilde
            if backcasts:
                sigma2_direct[t] += backcast * lam_rev[:backcasts].sum()
            if t:
                sigma2_direct[t] += np.sum(lam_rev[-t:] * fresids[max(0, t - 1000) : t])
        assert_almost_equal(sigma2_direct, sigma2)

        recpy.figarch_recursion(
            parameters,
            fresids,
            sigma2,
            p,
            q,
            nobs,
            trunc_lag,
            backcast,
            self.var_bounds,
        )
        sigma2_numba = sigma2.copy()
        recpy.figarch_recursion_python(
            parameters,
            fresids,
            sigma2,
            p,
            q,
            nobs,
            trunc_lag,
            backcast,
            self.var_bounds,
        )
        sigma2_python = sigma2.copy()
        rec.figarch_recursion(
            parameters,
            fresids,
            sigma2,
            p,
            q,
            nobs,
            trunc_lag,
            backcast,
            self.var_bounds,
        )
        assert_almost_equal(sigma2_numba, sigma2)
        assert_almost_equal(sigma2_python, sigma2)

    def test_figarch_weights(self):
        parameters = np.array([1.0, 0.4])
        lam = rec.figarch_weights(parameters[1:], 0, 0, trunc_lag=1000)
        lam_direct = np.empty_like(lam)
        lam_direct[0] = parameters[-1]
        for i in range(1, 1000):
            lam_direct[i] = (i - parameters[-1]) / (i + 1) * lam_direct[i - 1]
        assert_almost_equal(lam, lam_direct)

    @pytest.mark.skipif(
        missing_numba or missing_extension, reason="numba not installed"
    )
    def test_garch_performance(self):
        garch_setup = """
parameters = np.array([.1, .4, .3, .2])
fresids = resids ** 2.0
sresids = np.sign(resids)
        """

        garch_first = """
recpy.garch_recursion(parameters, fresids, sresids, sigma2, 1, 1, 1, nobs,
backcast, var_bounds)
        """
        garch_second = """
rec.garch_recursion(parameters, fresids, sresids, sigma2, 1, 1, 1, nobs, backcast,
var_bounds)
        """
        timer = Timer(
            garch_first,
            "Numba",
            garch_second,
            "Cython",
            "GARCH",
            self.timer_setup + garch_setup,
        )
        timer.display()
        assert timer.ratio < 10.0
        if not (missing_numba or CYTHON_COVERAGE):
            assert 0.1 < timer.ratio

    @pytest.mark.skipif(
        missing_numba or missing_extension, reason="numba not installed"
    )
    def test_harch_performance(self):
        harch_setup = """
parameters = np.array([.1, .4, .3, .2])
lags = np.array([1, 5, 22], dtype=np.int32)
        """

        harch_first = """
recpy.harch_recursion(parameters, resids, sigma2, lags, nobs, backcast,
var_bounds)
        """

        harch_second = """
rec.harch_recursion(parameters, resids, sigma2, lags, nobs, backcast, var_bounds)
        """

        timer = Timer(
            harch_first,
            "Numba",
            harch_second,
            "Cython",
            "HARCH",
            self.timer_setup + harch_setup,
        )
        timer.display()
        assert timer.ratio < 10.0
        if not (missing_numba or CYTHON_COVERAGE):
            assert 0.1 < timer.ratio

    @pytest.mark.skipif(
        missing_numba or missing_extension, reason="numba not installed"
    )
    def test_egarch_performance(self):
        egarch_setup = """
parameters = np.array([0.0, 0.1, -0.1, 0.95])
p = o = q = 1
backcast = 0.0
lnsigma2 = np.empty_like(sigma2)
std_resids = np.empty_like(sigma2)
abs_std_resids = np.empty_like(sigma2)
        """

        egarch_first = """
recpy.egarch_recursion(parameters, resids, sigma2, p, o, q, nobs, backcast,
var_bounds, lnsigma2, std_resids, abs_std_resids)
"""

        egarch_second = """
rec.egarch_recursion(parameters, resids, sigma2, p, o, q, nobs, backcast,
var_bounds, lnsigma2, std_resids, abs_std_resids)
"""
        timer = Timer(
            egarch_first,
            "Numba",
            egarch_second,
            "Cython",
            "EGARCH",
            self.timer_setup + egarch_setup,
        )
        timer.display()
        assert timer.ratio < 10.0
        if not (missing_numba or CYTHON_COVERAGE):
            assert 0.1 < timer.ratio

    @pytest.mark.skipif(
        missing_numba or missing_extension, reason="numba not installed"
    )
    def test_midas_performance(self):
        midas_setup = """
from scipy.special import gamma
parameters = np.array([.1, 0.8, 0])
j = np.arange(1,22+1)
weights = gamma(j+0.6) / (gamma(j+1) * gamma(0.6))
weights = weights / weights.sum()
"""

        midas_first = """
recpy.midas_recursion(parameters, weights, resids, sigma2, nobs, backcast, var_bounds)
                """
        midas_second = """
rec.midas_recursion(parameters, weights, resids, sigma2, nobs, backcast, var_bounds)
"""
        timer = Timer(
            midas_first,
            "Numba",
            midas_second,
            "Cython",
            "MIDAS",
            self.timer_setup + midas_setup,
        )
        timer.display()
        assert timer.ratio < 10.0
        if not (missing_numba or CYTHON_COVERAGE):
            assert 0.1 < timer.ratio

    @pytest.mark.skipif(
        missing_numba or missing_extension, reason="numba not installed"
    )
    def test_figarch_performance(self):
        midas_setup = """
p = q = 1
trunc_lag = 1000
parameters = np.array([1.0, 0.2, 0.2, 0.04])
fresids = resids ** 2.0
"""

        midas_first = """
recpy.figarch_recursion(parameters, fresids, sigma2, p, q, nobs, trunc_lag, backcast, var_bounds)
                """
        midas_second = """
rec.figarch_recursion(parameters, fresids, sigma2, p, q, nobs, trunc_lag, backcast, var_bounds)
"""
        timer = Timer(
            midas_first,
            "Numba",
            midas_second,
            "Cython",
            "FIGARCH",
            self.timer_setup + midas_setup,
        )
        timer.display()
        assert timer.ratio < 10.0
        if not (missing_numba or CYTHON_COVERAGE):
            assert 0.1 < timer.ratio

    def test_garch_aparch_equiv(self):
        parameters = np.array([0.1, 0.1, 0.8])
        fresids = self.resids ** 2
        sresids = np.sign(self.resids)
        sigma2 = np.empty(1000)
        p = q = 1
        o = 0
        recpy.garch_recursion_python(
            parameters,
            fresids,
            sresids,
            sigma2,
            p,
            o,
            q,
            self.nobs,
            self.backcast,
            self.var_bounds,
        )
        sigma2_garch = sigma2.copy()

        parameters = np.array([0.1, 0.1, 0.8, 2])
        sigma2[:] = np.nan
        sigma2_delta = np.empty_like(sigma2)
        recpy.aparch_recursion_python(
            parameters,
            self.resids,
            np.abs(self.resids),
            sigma2,
            sigma2_delta,
            p,
            o,
            q,
            self.nobs,
            self.backcast,
            self.var_bounds,
        )
        assert_allclose(sigma2_garch, sigma2, atol=1e-6)

        sigma2[:] = np.nan
        recpy.aparch_recursion(
            parameters,
            self.resids,
            np.abs(self.resids),
            sigma2,
            sigma2_delta,
            p,
            o,
            q,
            self.nobs,
            self.backcast,
            self.var_bounds,
        )
        assert_allclose(sigma2_garch, sigma2, atol=1e-6)

        sigma2[:] = np.nan
        rec.aparch_recursion(
            parameters,
            self.resids,
            np.abs(self.resids),
            sigma2,
            sigma2_delta,
            p,
            o,
            q,
            self.nobs,
            self.backcast,
            self.var_bounds,
        )
        assert_allclose(sigma2_garch, sigma2, atol=1e-6)

    def test_asym_aparch_smoke(self):
        sigma2 = np.empty(1000)
        p = o = q = 1
        parameters = np.array([0.1, 0.1, 0.1, 0.8, 1.3])
        sigma2[:] = np.nan
        sigma2_delta = np.empty_like(sigma2)
        recpy.aparch_recursion_python(
            parameters,
            self.resids,
            np.abs(self.resids),
            sigma2,
            sigma2_delta,
            p,
            o,
            q,
            self.nobs,
            self.backcast,
            self.var_bounds,
        )
        assert np.all(np.isfinite(sigma2))
        sigma2_py = sigma2.copy()
        sigma2[:] = np.nan
        recpy.aparch_recursion(
            parameters,
            self.resids,
            np.abs(self.resids),
            sigma2,
            sigma2_delta,
            p,
            o,
            q,
            self.nobs,
            self.backcast,
            self.var_bounds,
        )
        assert np.all(np.isfinite(sigma2))
        assert_allclose(sigma2_py, sigma2)

        sigma2[:] = np.nan
        rec.aparch_recursion(
            parameters,
            self.resids,
            np.abs(self.resids),
            sigma2,
            sigma2_delta,
            p,
            o,
            q,
            self.nobs,
            self.backcast,
            self.var_bounds,
        )
        assert np.all(np.isfinite(sigma2))
        assert_allclose(sigma2_py, sigma2)


def test_bounds_check():
    var_bounds = np.array([0.1, 10])
    assert_almost_equal(recpy.bounds_check_python(-1.0, var_bounds), 0.1)
    assert_almost_equal(
        recpy.bounds_check_python(20.0, var_bounds), 10 + np.log(20.0 / 10.0)
    )
    assert_almost_equal(recpy.bounds_check_python(np.inf, var_bounds), 1010.0)

[((34, 13, 34, 87), 'pytest.mark.filterwarnings', 'pytest.mark.filterwarnings', ({(34, 40, 34, 86): '"""ignore::arch.compat.numba.PerformanceWarning"""'}, {}), "('ignore::arch.compat.numba.PerformanceWarning')", False, 'import pytest\n'), ((13, 18, 13, 61), 'os.environ.get', 'os.environ.get', ({(13, 33, 13, 55): '"""ARCH_CYTHON_COVERAGE"""', (13, 57, 13, 60): '"""0"""'}, {}), "('ARCH_CYTHON_COVERAGE', '0')", False, 'import os\n'), ((911, 5, 913, 5), 'pytest.mark.skipif', 'pytest.mark.skipif', (), '', False, 'import pytest\n'), ((942, 5, 944, 5), 'pytest.mark.skipif', 'pytest.mark.skipif', (), '', False, 'import pytest\n'), ((973, 5, 975, 5), 'pytest.mark.skipif', 'pytest.mark.skipif', (), '', False, 'import pytest\n'), ((1008, 5, 1010, 5), 'pytest.mark.skipif', 'pytest.mark.skipif', (), '', False, 'import pytest\n'), ((1039, 5, 1041, 5), 'pytest.mark.skipif', 'pytest.mark.skipif', (), '', False, 'import pytest\n'), ((1197, 17, 1197, 36), 'numpy.array', 'np.array', ({(1197, 26, 1197, 35): '[0.1, 10]'}, {}), '([0.1, 10])', True, 'import numpy as np\n'), ((101, 18, 101, 36), 'numpy.random.RandomState', 'RandomState', ({(101, 30, 101, 35): '12345'}, {}), '(12345)', False, 'from numpy.random import RandomState\n'), ((103, 21, 103, 46), 'numpy.zeros_like', 'np.zeros_like', ({(103, 35, 103, 45): 'cls.resids'}, {}), '(cls.resids)', True, 'import numpy as np\n'), ((105, 21, 105, 65), 'numpy.array', 'np.array', ({(105, 30, 105, 64): '[var / 1000000.0, var * 1000000.0]'}, {}), '([var / 1000000.0, var * 1000000.0])', True, 'import numpy as np\n'), ((126, 21, 126, 51), 'numpy.array', 'np.array', ({(126, 30, 126, 50): '[0.1, 0.4, 0.3, 0.2]'}, {}), '([0.1, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((128, 18, 128, 33), 'numpy.sign', 'np.sign', ({(128, 26, 128, 32): 'resids'}, {}), '(resids)', True, 'import numpy as np\n'), ((130, 8, 141, 9), 'arch.univariate.recursions_python.garch_recursion', 'recpy.garch_recursion', ({(131, 12, 131, 22): 'parameters', (132, 12, 132, 19): 'fresids', (133, 12, 133, 19): 'sresids', (134, 12, 134, 18): 'sigma2', (135, 12, 135, 13): '(1)', (136, 12, 136, 13): '(1)', (137, 12, 137, 13): '(1)', (138, 12, 138, 16): 'nobs', (139, 12, 139, 20): 'backcast', (140, 12, 140, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sresids, sigma2, 1, 1, 1, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((143, 8, 154, 9), 'arch.univariate.recursions_python.garch_recursion_python', 'recpy.garch_recursion_python', ({(144, 12, 144, 22): 'parameters', (145, 12, 145, 19): 'fresids', (146, 12, 146, 19): 'sresids', (147, 12, 147, 18): 'sigma2', (148, 12, 148, 13): '(1)', (149, 12, 149, 13): '(1)', (150, 12, 150, 13): '(1)', (151, 12, 151, 16): 'nobs', (152, 12, 152, 20): 'backcast', (153, 12, 153, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sresids, sigma2, 1, 1, 1,\n    nobs, backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((168, 8, 168, 49), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(168, 28, 168, 40): 'sigma2_numba', (168, 42, 168, 48): 'sigma2'}, {}), '(sigma2_numba, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((169, 8, 169, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(169, 28, 169, 41): 'sigma2_python', (169, 43, 169, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((171, 21, 171, 52), 'numpy.array', 'np.array', ({(171, 30, 171, 51): '[0.1, -0.4, 0.3, 0.2]'}, {}), '([0.1, -0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((172, 8, 183, 9), 'arch.univariate.recursions_python.garch_recursion_python', 'recpy.garch_recursion_python', ({(173, 12, 173, 22): 'parameters', (174, 12, 174, 19): 'fresids', (175, 12, 175, 19): 'sresids', (176, 12, 176, 18): 'sigma2', (177, 12, 177, 13): '(1)', (178, 12, 178, 13): '(1)', (179, 12, 179, 13): '(1)', (180, 12, 180, 16): 'nobs', (181, 12, 181, 20): 'backcast', (182, 12, 182, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sresids, sigma2, 1, 1, 1,\n    nobs, backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((184, 15, 184, 54), 'numpy.all', 'np.all', ({(184, 22, 184, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((185, 15, 185, 58), 'numpy.all', 'np.all', ({(185, 22, 185, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((187, 21, 187, 47), 'numpy.array', 'np.array', ({(187, 30, 187, 46): '[0.1, 0.4, 3, 2]'}, {}), '([0.1, 0.4, 3, 2])', True, 'import numpy as np\n'), ((188, 8, 199, 9), 'arch.univariate.recursions_python.garch_recursion_python', 'recpy.garch_recursion_python', ({(189, 12, 189, 22): 'parameters', (190, 12, 190, 19): 'fresids', (191, 12, 191, 19): 'sresids', (192, 12, 192, 18): 'sigma2', (193, 12, 193, 13): '(1)', (194, 12, 194, 13): '(1)', (195, 12, 195, 13): '(1)', (196, 12, 196, 16): 'nobs', (197, 12, 197, 20): 'backcast', (198, 12, 198, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sresids, sigma2, 1, 1, 1,\n    nobs, backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((200, 15, 200, 54), 'numpy.all', 'np.all', ({(200, 22, 200, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((201, 15, 201, 58), 'numpy.all', 'np.all', ({(201, 22, 201, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((203, 21, 203, 51), 'numpy.array', 'np.array', ({(203, 30, 203, 50): '[0.1, 0.4, 0.3, 0.2]'}, {}), '([0.1, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((206, 8, 217, 9), 'arch.univariate.recursions_python.garch_recursion_python', 'recpy.garch_recursion_python', ({(207, 12, 207, 22): 'parameters', (208, 12, 208, 23): 'mod_fresids', (209, 12, 209, 19): 'sresids', (210, 12, 210, 18): 'sigma2', (211, 12, 211, 13): '(1)', (212, 12, 212, 13): '(1)', (213, 12, 213, 13): '(1)', (214, 12, 214, 16): 'nobs', (215, 12, 215, 20): 'backcast', (216, 12, 216, 27): 'self.var_bounds'}, {}), '(parameters, mod_fresids, sresids, sigma2, 1, 1,\n    1, nobs, backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((218, 15, 218, 54), 'numpy.all', 'np.all', ({(218, 22, 218, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((219, 15, 219, 58), 'numpy.all', 'np.all', ({(219, 22, 219, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((232, 15, 232, 54), 'numpy.all', 'np.all', ({(232, 22, 232, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((233, 15, 233, 58), 'numpy.all', 'np.all', ({(233, 22, 233, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((239, 21, 239, 51), 'numpy.array', 'np.array', ({(239, 30, 239, 50): '[0.1, 0.4, 0.3, 0.2]'}, {}), '([0.1, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((240, 15, 240, 51), 'numpy.array', 'np.array', (), '', True, 'import numpy as np\n'), ((241, 8, 243, 9), 'arch.univariate.recursions_python.harch_recursion_python', 'recpy.harch_recursion_python', ({(242, 12, 242, 22): 'parameters', (242, 24, 242, 30): 'resids', (242, 32, 242, 38): 'sigma2', (242, 40, 242, 44): 'lags', (242, 46, 242, 50): 'nobs', (242, 52, 242, 60): 'backcast', (242, 62, 242, 77): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, lags, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((245, 8, 247, 9), 'arch.univariate.recursions_python.harch_recursion', 'recpy.harch_recursion', ({(246, 12, 246, 22): 'parameters', (246, 24, 246, 30): 'resids', (246, 32, 246, 38): 'sigma2', (246, 40, 246, 44): 'lags', (246, 46, 246, 50): 'nobs', (246, 52, 246, 60): 'backcast', (246, 62, 246, 77): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, lags, nobs, backcast,\n    self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((252, 8, 252, 49), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(252, 28, 252, 40): 'sigma2_numba', (252, 42, 252, 48): 'sigma2'}, {}), '(sigma2_numba, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((253, 8, 253, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(253, 28, 253, 41): 'sigma2_python', (253, 43, 253, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((255, 21, 255, 53), 'numpy.array', 'np.array', ({(255, 30, 255, 52): '[-0.1, -0.4, 0.3, 0.2]'}, {}), '([-0.1, -0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((256, 8, 258, 9), 'arch.univariate.recursions_python.harch_recursion_python', 'recpy.harch_recursion_python', ({(257, 12, 257, 22): 'parameters', (257, 24, 257, 30): 'resids', (257, 32, 257, 38): 'sigma2', (257, 40, 257, 44): 'lags', (257, 46, 257, 50): 'nobs', (257, 52, 257, 60): 'backcast', (257, 62, 257, 77): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, lags, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((259, 15, 259, 54), 'numpy.all', 'np.all', ({(259, 22, 259, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((260, 15, 260, 58), 'numpy.all', 'np.all', ({(260, 22, 260, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((262, 21, 262, 47), 'numpy.array', 'np.array', ({(262, 30, 262, 46): '[0.1, 400000000.0, 3, 2]'}, {}), '([0.1, 400000000.0, 3, 2])', True, 'import numpy as np\n'), ((263, 8, 265, 9), 'arch.univariate.recursions_python.harch_recursion_python', 'recpy.harch_recursion_python', ({(264, 12, 264, 22): 'parameters', (264, 24, 264, 30): 'resids', (264, 32, 264, 38): 'sigma2', (264, 40, 264, 44): 'lags', (264, 46, 264, 50): 'nobs', (264, 52, 264, 60): 'backcast', (264, 62, 264, 77): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, lags, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((266, 15, 266, 54), 'numpy.all', 'np.all', ({(266, 22, 266, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((267, 15, 267, 58), 'numpy.all', 'np.all', ({(267, 22, 267, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((269, 21, 269, 47), 'numpy.array', 'np.array', ({(269, 30, 269, 46): '[0.1, 400000000.0, 3, 2]'}, {}), '([0.1, 400000000.0, 3, 2])', True, 'import numpy as np\n'), ((272, 8, 274, 9), 'arch.univariate.recursions_python.harch_recursion_python', 'recpy.harch_recursion_python', ({(273, 12, 273, 22): 'parameters', (273, 24, 273, 34): 'mod_resids', (273, 36, 273, 42): 'sigma2', (273, 44, 273, 48): 'lags', (273, 50, 273, 54): 'nobs', (273, 56, 273, 64): 'backcast', (273, 66, 273, 81): 'self.var_bounds'}, {}), '(parameters, mod_resids, sigma2, lags, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((275, 15, 275, 54), 'numpy.all', 'np.all', ({(275, 22, 275, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((276, 15, 276, 58), 'numpy.all', 'np.all', ({(276, 22, 276, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((280, 15, 280, 54), 'numpy.all', 'np.all', ({(280, 22, 280, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((281, 15, 281, 58), 'numpy.all', 'np.all', ({(281, 22, 281, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((287, 21, 287, 51), 'numpy.array', 'np.array', ({(287, 30, 287, 50): '[0.1, 0.4, 0.3, 0.2]'}, {}), '([0.1, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((290, 8, 292, 9), 'arch.univariate.recursions_python.arch_recursion_python', 'recpy.arch_recursion_python', ({(291, 12, 291, 22): 'parameters', (291, 24, 291, 30): 'resids', (291, 32, 291, 38): 'sigma2', (291, 40, 291, 41): 'p', (291, 43, 291, 47): 'nobs', (291, 49, 291, 57): 'backcast', (291, 59, 291, 74): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, p, nobs, backcast,\n    self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((294, 8, 296, 9), 'arch.univariate.recursions_python.arch_recursion', 'recpy.arch_recursion', ({(295, 12, 295, 22): 'parameters', (295, 24, 295, 30): 'resids', (295, 32, 295, 38): 'sigma2', (295, 40, 295, 41): 'p', (295, 43, 295, 47): 'nobs', (295, 49, 295, 57): 'backcast', (295, 59, 295, 74): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, p, nobs, backcast, self.\n    var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((301, 8, 301, 49), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(301, 28, 301, 40): 'sigma2_numba', (301, 42, 301, 48): 'sigma2'}, {}), '(sigma2_numba, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((302, 8, 302, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(302, 28, 302, 41): 'sigma2_python', (302, 43, 302, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((304, 21, 304, 53), 'numpy.array', 'np.array', ({(304, 30, 304, 52): '[-0.1, -0.4, 0.3, 0.2]'}, {}), '([-0.1, -0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((305, 8, 307, 9), 'arch.univariate.recursions_python.arch_recursion_python', 'recpy.arch_recursion_python', ({(306, 12, 306, 22): 'parameters', (306, 24, 306, 30): 'resids', (306, 32, 306, 38): 'sigma2', (306, 40, 306, 41): 'p', (306, 43, 306, 47): 'nobs', (306, 49, 306, 57): 'backcast', (306, 59, 306, 74): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, p, nobs, backcast,\n    self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((308, 15, 308, 54), 'numpy.all', 'np.all', ({(308, 22, 308, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((309, 15, 309, 58), 'numpy.all', 'np.all', ({(309, 22, 309, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((311, 21, 311, 47), 'numpy.array', 'np.array', ({(311, 30, 311, 46): '[0.1, 400000000.0, 3, 2]'}, {}), '([0.1, 400000000.0, 3, 2])', True, 'import numpy as np\n'), ((312, 8, 314, 9), 'arch.univariate.recursions_python.arch_recursion_python', 'recpy.arch_recursion_python', ({(313, 12, 313, 22): 'parameters', (313, 24, 313, 30): 'resids', (313, 32, 313, 38): 'sigma2', (313, 40, 313, 41): 'p', (313, 43, 313, 47): 'nobs', (313, 49, 313, 57): 'backcast', (313, 59, 313, 74): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, p, nobs, backcast,\n    self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((315, 15, 315, 54), 'numpy.all', 'np.all', ({(315, 22, 315, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((316, 15, 316, 58), 'numpy.all', 'np.all', ({(316, 22, 316, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((320, 8, 322, 9), 'arch.univariate.recursions_python.arch_recursion_python', 'recpy.arch_recursion_python', ({(321, 12, 321, 22): 'parameters', (321, 24, 321, 34): 'mod_resids', (321, 36, 321, 42): 'sigma2', (321, 44, 321, 45): 'p', (321, 47, 321, 51): 'nobs', (321, 53, 321, 61): 'backcast', (321, 63, 321, 78): 'self.var_bounds'}, {}), '(parameters, mod_resids, sigma2, p, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((323, 15, 323, 54), 'numpy.all', 'np.all', ({(323, 22, 323, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((324, 15, 324, 58), 'numpy.all', 'np.all', ({(324, 22, 324, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((328, 15, 328, 54), 'numpy.all', 'np.all', ({(328, 22, 328, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((329, 15, 329, 58), 'numpy.all', 'np.all', ({(329, 22, 329, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((335, 21, 335, 51), 'numpy.array', 'np.array', ({(335, 30, 335, 50): '[0.1, 0.4, 0.3, 0.2]'}, {}), '([0.1, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((337, 18, 337, 33), 'numpy.sign', 'np.sign', ({(337, 26, 337, 32): 'resids'}, {}), '(resids)', True, 'import numpy as np\n'), ((339, 8, 350, 9), 'arch.univariate.recursions_python.garch_recursion', 'recpy.garch_recursion', ({(340, 12, 340, 22): 'parameters', (341, 12, 341, 19): 'fresids', (342, 12, 342, 19): 'sresids', (343, 12, 343, 18): 'sigma2', (344, 12, 344, 13): '(1)', (345, 12, 345, 13): '(1)', (346, 12, 346, 13): '(1)', (347, 12, 347, 16): 'nobs', (348, 12, 348, 20): 'backcast', (349, 12, 349, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sresids, sigma2, 1, 1, 1, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((364, 8, 364, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(364, 28, 364, 41): 'sigma2_python', (364, 43, 364, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((370, 21, 370, 51), 'numpy.array', 'np.array', ({(370, 30, 370, 50): '[0.1, 0.4, 0.3, 0.2]'}, {}), '([0.1, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((372, 18, 372, 33), 'numpy.sign', 'np.sign', ({(372, 26, 372, 32): 'resids'}, {}), '(resids)', True, 'import numpy as np\n'), ((403, 8, 403, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(403, 28, 403, 41): 'sigma2_python', (403, 43, 403, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((409, 21, 409, 46), 'numpy.array', 'np.array', ({(409, 30, 409, 45): '[0.1, 0.4, 0.3]'}, {}), '([0.1, 0.4, 0.3])', True, 'import numpy as np\n'), ((411, 18, 411, 33), 'numpy.sign', 'np.sign', ({(411, 26, 411, 32): 'resids'}, {}), '(resids)', True, 'import numpy as np\n'), ((413, 8, 424, 9), 'arch.univariate.recursions_python.garch_recursion', 'recpy.garch_recursion', ({(414, 12, 414, 22): 'parameters', (415, 12, 415, 19): 'fresids', (416, 12, 416, 19): 'sresids', (417, 12, 417, 18): 'sigma2', (418, 12, 418, 13): '(1)', (419, 12, 419, 13): '(1)', (420, 12, 420, 13): '(0)', (421, 12, 421, 16): 'nobs', (422, 12, 422, 20): 'backcast', (423, 12, 423, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sresids, sigma2, 1, 1, 0, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((438, 8, 438, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(438, 28, 438, 41): 'sigma2_python', (438, 43, 438, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((444, 21, 444, 46), 'numpy.array', 'np.array', ({(444, 30, 444, 45): '[0.1, 0.4, 0.3]'}, {}), '([0.1, 0.4, 0.3])', True, 'import numpy as np\n'), ((446, 18, 446, 33), 'numpy.sign', 'np.sign', ({(446, 26, 446, 32): 'resids'}, {}), '(resids)', True, 'import numpy as np\n'), ((448, 8, 459, 9), 'arch.univariate.recursions_python.garch_recursion', 'recpy.garch_recursion', ({(449, 12, 449, 22): 'parameters', (450, 12, 450, 19): 'fresids', (451, 12, 451, 19): 'sresids', (452, 12, 452, 18): 'sigma2', (453, 12, 453, 13): '(0)', (454, 12, 454, 13): '(1)', (455, 12, 455, 13): '(1)', (456, 12, 456, 16): 'nobs', (457, 12, 457, 20): 'backcast', (458, 12, 458, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sresids, sigma2, 0, 1, 1, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((473, 8, 473, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(473, 28, 473, 41): 'sigma2_python', (473, 43, 473, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((479, 21, 479, 51), 'numpy.array', 'np.array', ({(479, 30, 479, 50): '[0.1, 0.4, 0.3, 0.2]'}, {}), '([0.1, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((481, 18, 481, 33), 'numpy.sign', 'np.sign', ({(481, 26, 481, 32): 'resids'}, {}), '(resids)', True, 'import numpy as np\n'), ((483, 8, 494, 9), 'arch.univariate.recursions_python.garch_recursion', 'recpy.garch_recursion', ({(484, 12, 484, 22): 'parameters', (485, 12, 485, 19): 'fresids', (486, 12, 486, 19): 'sresids', (487, 12, 487, 18): 'sigma2', (488, 12, 488, 13): '(1)', (489, 12, 489, 13): '(0)', (490, 12, 490, 13): '(1)', (491, 12, 491, 16): 'nobs', (492, 12, 492, 20): 'backcast', (493, 12, 493, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sresids, sigma2, 1, 0, 1, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((508, 8, 508, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(508, 28, 508, 41): 'sigma2_python', (508, 43, 508, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((514, 21, 514, 51), 'numpy.array', 'np.array', ({(514, 30, 514, 50): '[0.1, 0.4, 0.3, 0.2]'}, {}), '([0.1, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((516, 18, 516, 33), 'numpy.sign', 'np.sign', ({(516, 26, 516, 32): 'resids'}, {}), '(resids)', True, 'import numpy as np\n'), ((535, 8, 535, 49), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(535, 28, 535, 40): 'sigma2_garch', (535, 42, 535, 48): 'sigma2'}, {}), '(sigma2_garch, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((541, 21, 541, 53), 'numpy.array', 'np.array', ({(541, 30, 541, 52): '[1e+100, 0.4, 0.3, 0.2]'}, {}), '([1e+100, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((542, 15, 542, 51), 'numpy.array', 'np.array', (), '', True, 'import numpy as np\n'), ((543, 8, 545, 9), 'arch.univariate.recursions_python.harch_recursion', 'recpy.harch_recursion', ({(544, 12, 544, 22): 'parameters', (544, 24, 544, 30): 'resids', (544, 32, 544, 38): 'sigma2', (544, 40, 544, 44): 'lags', (544, 46, 544, 50): 'nobs', (544, 52, 544, 60): 'backcast', (544, 62, 544, 77): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, lags, nobs, backcast,\n    self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((550, 8, 550, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(550, 28, 550, 41): 'sigma2_python', (550, 43, 550, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((551, 15, 551, 54), 'numpy.all', 'np.all', ({(551, 22, 551, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((552, 15, 552, 58), 'numpy.all', 'np.all', ({(552, 22, 552, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((554, 21, 554, 54), 'numpy.array', 'np.array', ({(554, 30, 554, 53): '[-1e+100, 0.4, 0.3, 0.2]'}, {}), '([-1e+100, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((555, 8, 557, 9), 'arch.univariate.recursions_python.harch_recursion', 'recpy.harch_recursion', ({(556, 12, 556, 22): 'parameters', (556, 24, 556, 30): 'resids', (556, 32, 556, 38): 'sigma2', (556, 40, 556, 44): 'lags', (556, 46, 556, 50): 'nobs', (556, 52, 556, 60): 'backcast', (556, 62, 556, 77): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, lags, nobs, backcast,\n    self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((562, 8, 562, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(562, 28, 562, 41): 'sigma2_python', (562, 43, 562, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((563, 8, 563, 58), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(563, 28, 563, 34): 'sigma2', (563, 36, 563, 57): 'self.var_bounds[:, (0)]'}, {}), '(sigma2, self.var_bounds[:, (0)])', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((565, 21, 565, 53), 'numpy.array', 'np.array', ({(565, 30, 565, 52): '[1e+100, 0.4, 0.3, 0.2]'}, {}), '([1e+100, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((567, 18, 567, 33), 'numpy.sign', 'np.sign', ({(567, 26, 567, 32): 'resids'}, {}), '(resids)', True, 'import numpy as np\n'), ((569, 8, 580, 9), 'arch.univariate.recursions_python.garch_recursion', 'recpy.garch_recursion', ({(570, 12, 570, 22): 'parameters', (571, 12, 571, 19): 'fresids', (572, 12, 572, 19): 'sresids', (573, 12, 573, 18): 'sigma2', (574, 12, 574, 13): '(1)', (575, 12, 575, 13): '(1)', (576, 12, 576, 13): '(1)', (577, 12, 577, 16): 'nobs', (578, 12, 578, 20): 'backcast', (579, 12, 579, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sresids, sigma2, 1, 1, 1, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((594, 8, 594, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(594, 28, 594, 41): 'sigma2_python', (594, 43, 594, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((595, 15, 595, 54), 'numpy.all', 'np.all', ({(595, 22, 595, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((596, 15, 596, 58), 'numpy.all', 'np.all', ({(596, 22, 596, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((598, 21, 598, 54), 'numpy.array', 'np.array', ({(598, 30, 598, 53): '[-1e+100, 0.4, 0.3, 0.2]'}, {}), '([-1e+100, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((599, 8, 610, 9), 'arch.univariate.recursions_python.garch_recursion', 'recpy.garch_recursion', ({(600, 12, 600, 22): 'parameters', (601, 12, 601, 19): 'fresids', (602, 12, 602, 19): 'sresids', (603, 12, 603, 18): 'sigma2', (604, 12, 604, 13): '(1)', (605, 12, 605, 13): '(1)', (606, 12, 606, 13): '(1)', (607, 12, 607, 16): 'nobs', (608, 12, 608, 20): 'backcast', (609, 12, 609, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sresids, sigma2, 1, 1, 1, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((624, 8, 624, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(624, 28, 624, 41): 'sigma2_python', (624, 43, 624, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((625, 8, 625, 58), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(625, 28, 625, 34): 'sigma2', (625, 36, 625, 57): 'self.var_bounds[:, (0)]'}, {}), '(sigma2, self.var_bounds[:, (0)])', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((627, 21, 627, 53), 'numpy.array', 'np.array', ({(627, 30, 627, 52): '[1e+100, 0.4, 0.3, 0.2]'}, {}), '([1e+100, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((628, 8, 630, 9), 'arch.univariate.recursions_python.arch_recursion', 'recpy.arch_recursion', ({(629, 12, 629, 22): 'parameters', (629, 24, 629, 30): 'resids', (629, 32, 629, 38): 'sigma2', (629, 40, 629, 41): '(3)', (629, 43, 629, 47): 'nobs', (629, 49, 629, 57): 'backcast', (629, 59, 629, 74): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, 3, nobs, backcast, self.\n    var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((635, 8, 635, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(635, 28, 635, 41): 'sigma2_python', (635, 43, 635, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((636, 15, 636, 54), 'numpy.all', 'np.all', ({(636, 22, 636, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((637, 15, 637, 58), 'numpy.all', 'np.all', ({(637, 22, 637, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((639, 21, 639, 54), 'numpy.array', 'np.array', ({(639, 30, 639, 53): '[-1e+100, 0.4, 0.3, 0.2]'}, {}), '([-1e+100, 0.4, 0.3, 0.2])', True, 'import numpy as np\n'), ((640, 8, 642, 9), 'arch.univariate.recursions_python.arch_recursion', 'recpy.arch_recursion', ({(641, 12, 641, 22): 'parameters', (641, 24, 641, 30): 'resids', (641, 32, 641, 38): 'sigma2', (641, 40, 641, 41): '(3)', (641, 43, 641, 47): 'nobs', (641, 49, 641, 57): 'backcast', (641, 59, 641, 74): 'self.var_bounds'}, {}), '(parameters, resids, sigma2, 3, nobs, backcast, self.\n    var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((647, 8, 647, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(647, 28, 647, 41): 'sigma2_python', (647, 43, 647, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((648, 8, 648, 58), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(648, 28, 648, 34): 'sigma2', (648, 36, 648, 57): 'self.var_bounds[:, (0)]'}, {}), '(sigma2, self.var_bounds[:, (0)])', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((652, 21, 652, 53), 'numpy.array', 'np.array', ({(652, 30, 652, 52): '[0.0, 0.1, -0.1, 0.95]'}, {}), '([0.0, 0.1, -0.1, 0.95])', True, 'import numpy as np\n'), ((657, 19, 657, 40), 'numpy.empty_like', 'np.empty_like', ({(657, 33, 657, 39): 'sigma2'}, {}), '(sigma2)', True, 'import numpy as np\n'), ((658, 21, 658, 42), 'numpy.empty_like', 'np.empty_like', ({(658, 35, 658, 41): 'sigma2'}, {}), '(sigma2)', True, 'import numpy as np\n'), ((659, 25, 659, 46), 'numpy.empty_like', 'np.empty_like', ({(659, 39, 659, 45): 'sigma2'}, {}), '(sigma2)', True, 'import numpy as np\n'), ((660, 8, 673, 9), 'arch.univariate.recursions_python.egarch_recursion', 'recpy.egarch_recursion', ({(661, 12, 661, 22): 'parameters', (662, 12, 662, 18): 'resids', (663, 12, 663, 18): 'sigma2', (664, 12, 664, 13): 'p', (665, 12, 665, 13): 'o', (666, 12, 666, 13): 'q', (667, 12, 667, 16): 'nobs', (668, 12, 668, 20): 'backcast', (669, 12, 669, 22): 'var_bounds', (670, 12, 670, 20): 'lnsigma2', (671, 12, 671, 22): 'std_resids', (672, 12, 672, 26): 'abs_std_resids'}, {}), '(parameters, resids, sigma2, p, o, q, nobs, backcast,\n    var_bounds, lnsigma2, std_resids, abs_std_resids)', True, 'import arch.univariate.recursions_python as recpy\n'), ((675, 8, 688, 9), 'arch.univariate.recursions_python.egarch_recursion_python', 'recpy.egarch_recursion_python', ({(676, 12, 676, 22): 'parameters', (677, 12, 677, 18): 'resids', (678, 12, 678, 18): 'sigma2', (679, 12, 679, 13): 'p', (680, 12, 680, 13): 'o', (681, 12, 681, 13): 'q', (682, 12, 682, 16): 'nobs', (683, 12, 683, 20): 'backcast', (684, 12, 684, 22): 'var_bounds', (685, 12, 685, 20): 'lnsigma2', (686, 12, 686, 22): 'std_resids', (687, 12, 687, 26): 'abs_std_resids'}, {}), '(parameters, resids, sigma2, p, o, q, nobs,\n    backcast, var_bounds, lnsigma2, std_resids, abs_std_resids)', True, 'import arch.univariate.recursions_python as recpy\n'), ((704, 8, 704, 49), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(704, 28, 704, 40): 'sigma2_numba', (704, 42, 704, 48): 'sigma2'}, {}), '(sigma2_numba, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((705, 8, 705, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(705, 28, 705, 41): 'sigma2_python', (705, 43, 705, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((707, 21, 707, 39), 'numpy.sqrt', 'np.sqrt', ({(707, 29, 707, 38): '2 / np.pi'}, {}), '(2 / np.pi)', True, 'import numpy as np\n'), ((718, 8, 718, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(718, 28, 718, 41): 'sigma2_python', (718, 43, 718, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((720, 21, 720, 56), 'numpy.array', 'np.array', ({(720, 30, 720, 55): '[-100.0, 0.1, -0.1, 0.95]'}, {}), '([-100.0, 0.1, -0.1, 0.95])', True, 'import numpy as np\n'), ((721, 8, 734, 9), 'arch.univariate.recursions_python.egarch_recursion_python', 'recpy.egarch_recursion_python', ({(722, 12, 722, 22): 'parameters', (723, 12, 723, 18): 'resids', (724, 12, 724, 18): 'sigma2', (725, 12, 725, 13): 'p', (726, 12, 726, 13): 'o', (727, 12, 727, 13): 'q', (728, 12, 728, 16): 'nobs', (729, 12, 729, 20): 'backcast', (730, 12, 730, 22): 'var_bounds', (731, 12, 731, 20): 'lnsigma2', (732, 12, 732, 22): 'std_resids', (733, 12, 733, 26): 'abs_std_resids'}, {}), '(parameters, resids, sigma2, p, o, q, nobs,\n    backcast, var_bounds, lnsigma2, std_resids, abs_std_resids)', True, 'import arch.univariate.recursions_python as recpy\n'), ((735, 15, 735, 54), 'numpy.all', 'np.all', ({(735, 22, 735, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((736, 15, 736, 58), 'numpy.all', 'np.all', ({(736, 22, 736, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((738, 21, 738, 52), 'numpy.array', 'np.array', ({(738, 30, 738, 51): '[0.0, 0.1, -0.1, 9.5]'}, {}), '([0.0, 0.1, -0.1, 9.5])', True, 'import numpy as np\n'), ((739, 8, 752, 9), 'arch.univariate.recursions_python.egarch_recursion_python', 'recpy.egarch_recursion_python', ({(740, 12, 740, 22): 'parameters', (741, 12, 741, 18): 'resids', (742, 12, 742, 18): 'sigma2', (743, 12, 743, 13): 'p', (744, 12, 744, 13): 'o', (745, 12, 745, 13): 'q', (746, 12, 746, 16): 'nobs', (747, 12, 747, 20): 'backcast', (748, 12, 748, 22): 'var_bounds', (749, 12, 749, 20): 'lnsigma2', (750, 12, 750, 22): 'std_resids', (751, 12, 751, 26): 'abs_std_resids'}, {}), '(parameters, resids, sigma2, p, o, q, nobs,\n    backcast, var_bounds, lnsigma2, std_resids, abs_std_resids)', True, 'import arch.univariate.recursions_python as recpy\n'), ((753, 15, 753, 54), 'numpy.all', 'np.all', ({(753, 22, 753, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((754, 15, 754, 58), 'numpy.all', 'np.all', ({(754, 22, 754, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((756, 21, 756, 53), 'numpy.array', 'np.array', ({(756, 30, 756, 52): '[0.0, 0.1, -0.1, 0.95]'}, {}), '([0.0, 0.1, -0.1, 0.95])', True, 'import numpy as np\n'), ((759, 8, 772, 9), 'arch.univariate.recursions_python.egarch_recursion_python', 'recpy.egarch_recursion_python', ({(760, 12, 760, 22): 'parameters', (761, 12, 761, 18): 'resids', (762, 12, 762, 18): 'sigma2', (763, 12, 763, 13): 'p', (764, 12, 764, 13): 'o', (765, 12, 765, 13): 'q', (766, 12, 766, 16): 'nobs', (767, 12, 767, 20): 'backcast', (768, 12, 768, 22): 'var_bounds', (769, 12, 769, 20): 'lnsigma2', (770, 12, 770, 22): 'std_resids', (771, 12, 771, 26): 'abs_std_resids'}, {}), '(parameters, resids, sigma2, p, o, q, nobs,\n    backcast, var_bounds, lnsigma2, std_resids, abs_std_resids)', True, 'import arch.univariate.recursions_python as recpy\n'), ((773, 15, 773, 54), 'numpy.all', 'np.all', ({(773, 22, 773, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((774, 15, 774, 58), 'numpy.all', 'np.all', ({(774, 22, 774, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((780, 21, 780, 44), 'numpy.array', 'np.array', ({(780, 30, 780, 43): '[0.1, 0.8, 0]'}, {}), '([0.1, 0.8, 0])', True, 'import numpy as np\n'), ((781, 12, 781, 32), 'numpy.arange', 'np.arange', ({(781, 22, 781, 23): '1', (781, 25, 781, 31): '22 + 1'}, {}), '(1, 22 + 1)', True, 'import numpy as np\n'), ((784, 8, 786, 9), 'arch.univariate.recursions_python.midas_recursion', 'recpy.midas_recursion', ({(785, 12, 785, 22): 'parameters', (785, 24, 785, 31): 'weights', (785, 33, 785, 39): 'resids', (785, 41, 785, 47): 'sigma2', (785, 49, 785, 53): 'nobs', (785, 55, 785, 63): 'backcast', (785, 65, 785, 80): 'self.var_bounds'}, {}), '(parameters, weights, resids, sigma2, nobs, backcast,\n    self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((788, 8, 790, 9), 'arch.univariate.recursions_python.midas_recursion_python', 'recpy.midas_recursion_python', ({(789, 12, 789, 22): 'parameters', (789, 24, 789, 31): 'weights', (789, 33, 789, 39): 'resids', (789, 41, 789, 47): 'sigma2', (789, 49, 789, 53): 'nobs', (789, 55, 789, 63): 'backcast', (789, 65, 789, 80): 'self.var_bounds'}, {}), '(parameters, weights, resids, sigma2, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((795, 8, 795, 49), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(795, 28, 795, 40): 'sigma2_numba', (795, 42, 795, 48): 'sigma2'}, {}), '(sigma2_numba, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((796, 8, 796, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(796, 28, 796, 41): 'sigma2_python', (796, 43, 796, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((800, 8, 802, 9), 'arch.univariate.recursions_python.midas_recursion_python', 'recpy.midas_recursion_python', ({(801, 12, 801, 22): 'parameters', (801, 24, 801, 31): 'weights', (801, 33, 801, 43): 'mod_resids', (801, 45, 801, 51): 'sigma2', (801, 53, 801, 57): 'nobs', (801, 59, 801, 67): 'backcast', (801, 69, 801, 84): 'self.var_bounds'}, {}), '(parameters, weights, mod_resids, sigma2, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((803, 15, 803, 54), 'numpy.all', 'np.all', ({(803, 22, 803, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((804, 15, 804, 58), 'numpy.all', 'np.all', ({(804, 22, 804, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((806, 21, 806, 46), 'numpy.array', 'np.array', ({(806, 30, 806, 45): '[0.1, 100000000000.0, 0]'}, {}), '([0.1, 100000000000.0, 0])', True, 'import numpy as np\n'), ((807, 12, 807, 32), 'numpy.arange', 'np.arange', ({(807, 22, 807, 23): '1', (807, 25, 807, 31): '22 + 1'}, {}), '(1, 22 + 1)', True, 'import numpy as np\n'), ((810, 8, 812, 9), 'arch.univariate.recursions_python.midas_recursion_python', 'recpy.midas_recursion_python', ({(811, 12, 811, 22): 'parameters', (811, 24, 811, 31): 'weights', (811, 33, 811, 39): 'resids', (811, 41, 811, 47): 'sigma2', (811, 49, 811, 53): 'nobs', (811, 55, 811, 63): 'backcast', (811, 65, 811, 80): 'self.var_bounds'}, {}), '(parameters, weights, resids, sigma2, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((813, 15, 813, 54), 'numpy.all', 'np.all', ({(813, 22, 813, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((814, 15, 814, 58), 'numpy.all', 'np.all', ({(814, 22, 814, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((818, 15, 818, 54), 'numpy.all', 'np.all', ({(818, 22, 818, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((819, 15, 819, 58), 'numpy.all', 'np.all', ({(819, 22, 819, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((821, 21, 821, 45), 'numpy.array', 'np.array', ({(821, 30, 821, 44): '[0.1, -0.4, 0]'}, {}), '([0.1, -0.4, 0])', True, 'import numpy as np\n'), ((822, 8, 824, 9), 'arch.univariate.recursions_python.midas_recursion_python', 'recpy.midas_recursion_python', ({(823, 12, 823, 22): 'parameters', (823, 24, 823, 31): 'weights', (823, 33, 823, 39): 'resids', (823, 41, 823, 47): 'sigma2', (823, 49, 823, 53): 'nobs', (823, 55, 823, 63): 'backcast', (823, 65, 823, 80): 'self.var_bounds'}, {}), '(parameters, weights, resids, sigma2, nobs,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((825, 15, 825, 54), 'numpy.all', 'np.all', ({(825, 22, 825, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((826, 15, 826, 58), 'numpy.all', 'np.all', ({(826, 22, 826, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((830, 15, 830, 54), 'numpy.all', 'np.all', ({(830, 22, 830, 53): '(sigma2 >= self.var_bounds[:, (0)])'}, {}), '(sigma2 >= self.var_bounds[:, (0)])', True, 'import numpy as np\n'), ((831, 15, 831, 58), 'numpy.all', 'np.all', ({(831, 22, 831, 57): '(sigma2 <= 2 * self.var_bounds[:, (1)])'}, {}), '(sigma2 <= 2 * self.var_bounds[:, (1)])', True, 'import numpy as np\n'), ((836, 21, 836, 51), 'numpy.array', 'np.array', ({(836, 30, 836, 50): '[1.0, 0.2, 0.4, 0.3]'}, {}), '([1.0, 0.2, 0.4, 0.3])', True, 'import numpy as np\n'), ((854, 24, 854, 45), 'numpy.empty_like', 'np.empty_like', ({(854, 38, 854, 44): 'sigma2'}, {}), '(sigma2)', True, 'import numpy as np\n'), ((862, 8, 862, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(862, 28, 862, 41): 'sigma2_direct', (862, 43, 862, 49): 'sigma2'}, {}), '(sigma2_direct, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((864, 8, 874, 9), 'arch.univariate.recursions_python.figarch_recursion', 'recpy.figarch_recursion', ({(865, 12, 865, 22): 'parameters', (866, 12, 866, 19): 'fresids', (867, 12, 867, 18): 'sigma2', (868, 12, 868, 13): 'p', (869, 12, 869, 13): 'q', (870, 12, 870, 16): 'nobs', (871, 12, 871, 21): 'trunc_lag', (872, 12, 872, 20): 'backcast', (873, 12, 873, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sigma2, p, q, nobs, trunc_lag,\n    backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((876, 8, 886, 9), 'arch.univariate.recursions_python.figarch_recursion_python', 'recpy.figarch_recursion_python', ({(877, 12, 877, 22): 'parameters', (878, 12, 878, 19): 'fresids', (879, 12, 879, 18): 'sigma2', (880, 12, 880, 13): 'p', (881, 12, 881, 13): 'q', (882, 12, 882, 16): 'nobs', (883, 12, 883, 21): 'trunc_lag', (884, 12, 884, 20): 'backcast', (885, 12, 885, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sigma2, p, q, nobs,\n    trunc_lag, backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((899, 8, 899, 49), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(899, 28, 899, 40): 'sigma2_numba', (899, 42, 899, 48): 'sigma2'}, {}), '(sigma2_numba, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((900, 8, 900, 50), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(900, 28, 900, 41): 'sigma2_python', (900, 43, 900, 49): 'sigma2'}, {}), '(sigma2_python, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((903, 21, 903, 41), 'numpy.array', 'np.array', ({(903, 30, 903, 40): '[1.0, 0.4]'}, {}), '([1.0, 0.4])', True, 'import numpy as np\n'), ((905, 21, 905, 39), 'numpy.empty_like', 'np.empty_like', ({(905, 35, 905, 38): 'lam'}, {}), '(lam)', True, 'import numpy as np\n'), ((909, 8, 909, 44), 'numpy.testing.assert_almost_equal', 'assert_almost_equal', ({(909, 28, 909, 31): 'lam', (909, 33, 909, 43): 'lam_direct'}, {}), '(lam, lam_direct)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((1070, 21, 1070, 46), 'numpy.array', 'np.array', ({(1070, 30, 1070, 45): '[0.1, 0.1, 0.8]'}, {}), '([0.1, 0.1, 0.8])', True, 'import numpy as np\n'), ((1072, 18, 1072, 38), 'numpy.sign', 'np.sign', ({(1072, 26, 1072, 37): 'self.resids'}, {}), '(self.resids)', True, 'import numpy as np\n'), ((1073, 17, 1073, 31), 'numpy.empty', 'np.empty', ({(1073, 26, 1073, 30): '1000'}, {}), '(1000)', True, 'import numpy as np\n'), ((1076, 8, 1087, 9), 'arch.univariate.recursions_python.garch_recursion_python', 'recpy.garch_recursion_python', ({(1077, 12, 1077, 22): 'parameters', (1078, 12, 1078, 19): 'fresids', (1079, 12, 1079, 19): 'sresids', (1080, 12, 1080, 18): 'sigma2', (1081, 12, 1081, 13): 'p', (1082, 12, 1082, 13): 'o', (1083, 12, 1083, 13): 'q', (1084, 12, 1084, 21): 'self.nobs', (1085, 12, 1085, 25): 'self.backcast', (1086, 12, 1086, 27): 'self.var_bounds'}, {}), '(parameters, fresids, sresids, sigma2, p, o, q,\n    self.nobs, self.backcast, self.var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((1090, 21, 1090, 49), 'numpy.array', 'np.array', ({(1090, 30, 1090, 48): '[0.1, 0.1, 0.8, 2]'}, {}), '([0.1, 0.1, 0.8, 2])', True, 'import numpy as np\n'), ((1092, 23, 1092, 44), 'numpy.empty_like', 'np.empty_like', ({(1092, 37, 1092, 43): 'sigma2'}, {}), '(sigma2)', True, 'import numpy as np\n'), ((1106, 8, 1106, 56), 'numpy.testing.assert_allclose', 'assert_allclose', (), '', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((1122, 8, 1122, 56), 'numpy.testing.assert_allclose', 'assert_allclose', (), '', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((1138, 8, 1138, 56), 'numpy.testing.assert_allclose', 'assert_allclose', (), '', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((1141, 17, 1141, 31), 'numpy.empty', 'np.empty', ({(1141, 26, 1141, 30): '1000'}, {}), '(1000)', True, 'import numpy as np\n'), ((1143, 21, 1143, 56), 'numpy.array', 'np.array', ({(1143, 30, 1143, 55): '[0.1, 0.1, 0.1, 0.8, 1.3]'}, {}), '([0.1, 0.1, 0.1, 0.8, 1.3])', True, 'import numpy as np\n'), ((1145, 23, 1145, 44), 'numpy.empty_like', 'np.empty_like', ({(1145, 37, 1145, 43): 'sigma2'}, {}), '(sigma2)', True, 'import numpy as np\n'), ((1176, 8, 1176, 42), 'numpy.testing.assert_allclose', 'assert_allclose', ({(1176, 24, 1176, 33): 'sigma2_py', (1176, 35, 1176, 41): 'sigma2'}, {}), '(sigma2_py, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((1193, 8, 1193, 42), 'numpy.testing.assert_allclose', 'assert_allclose', ({(1193, 24, 1193, 33): 'sigma2_py', (1193, 35, 1193, 41): 'sigma2'}, {}), '(sigma2_py, sigma2)', False, 'from numpy.testing import assert_allclose, assert_almost_equal\n'), ((1198, 24, 1198, 67), 'arch.univariate.recursions_python.bounds_check_python', 'recpy.bounds_check_python', ({(1198, 50, 1198, 54): '(-1.0)', (1198, 56, 1198, 66): 'var_bounds'}, {}), '(-1.0, var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((1200, 8, 1200, 51), 'arch.univariate.recursions_python.bounds_check_python', 'recpy.bounds_check_python', ({(1200, 34, 1200, 38): '(20.0)', (1200, 40, 1200, 50): 'var_bounds'}, {}), '(20.0, var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((1202, 24, 1202, 69), 'arch.univariate.recursions_python.bounds_check_python', 'recpy.bounds_check_python', ({(1202, 50, 1202, 56): 'np.inf', (1202, 58, 1202, 68): 'var_bounds'}, {}), '(np.inf, var_bounds)', True, 'import arch.univariate.recursions_python as recpy\n'), ((93, 20, 93, 56), 'timeit.Timer', 'timeit.Timer', (), '', False, 'import timeit\n'), ((106, 25, 106, 47), 'numpy.ones', 'np.ones', ({(106, 33, 106, 46): '(cls.nobs, 2)'}, {}), '((cls.nobs, 2))', True, 'import numpy as np\n'), ((336, 18, 336, 32), 'numpy.abs', 'np.abs', ({(336, 25, 336, 31): 'resids'}, {}), '(resids)', True, 'import numpy as np\n'), ((371, 18, 371, 32), 'numpy.abs', 'np.abs', ({(371, 25, 371, 31): 'resids'}, {}), '(resids)', True, 'import numpy as np\n'), ((717, 24, 717, 43), 'numpy.exp', 'np.exp', ({(717, 31, 717, 42): 'lnsigma2[t]'}, {}), '(lnsigma2[t])', True, 'import numpy as np\n'), ((782, 18, 782, 32), 'scipy.special.gamma', 'gamma', ({(782, 24, 782, 31): '(j + 0.6)'}, {}), '(j + 0.6)', False, 'from scipy.special import gamma\n'), ((808, 18, 808, 32), 'scipy.special.gamma', 'gamma', ({(808, 24, 808, 31): '(j + 0.6)'}, {}), '(j + 0.6)', False, 'from scipy.special import gamma\n'), ((1096, 12, 1096, 31), 'numpy.abs', 'np.abs', ({(1096, 19, 1096, 30): 'self.resids'}, {}), '(self.resids)', True, 'import numpy as np\n'), ((1112, 12, 1112, 31), 'numpy.abs', 'np.abs', ({(1112, 19, 1112, 30): 'self.resids'}, {}), '(self.resids)', True, 'import numpy as np\n'), ((1128, 12, 1128, 31), 'numpy.abs', 'np.abs', ({(1128, 19, 1128, 30): 'self.resids'}, {}), '(self.resids)', True, 'import numpy as np\n'), ((1149, 12, 1149, 31), 'numpy.abs', 'np.abs', ({(1149, 19, 1149, 30): 'self.resids'}, {}), '(self.resids)', True, 'import numpy as np\n'), ((1159, 22, 1159, 41), 'numpy.isfinite', 'np.isfinite', ({(1159, 34, 1159, 40): 'sigma2'}, {}), '(sigma2)', True, 'import numpy as np\n'), ((1165, 12, 1165, 31), 'numpy.abs', 'np.abs', ({(1165, 19, 1165, 30): 'self.resids'}, {}), '(self.resids)', True, 'import numpy as np\n'), ((1175, 22, 1175, 41), 'numpy.isfinite', 'np.isfinite', ({(1175, 34, 1175, 40): 'sigma2'}, {}), '(sigma2)', True, 'import numpy as np\n'), ((1182, 12, 1182, 31), 'numpy.abs', 'np.abs', ({(1182, 19, 1182, 30): 'self.resids'}, {}), '(self.resids)', True, 'import numpy as np\n'), ((1192, 22, 1192, 41), 'numpy.isfinite', 'np.isfinite', ({(1192, 34, 1192, 40): 'sigma2'}, {}), '(sigma2)', True, 'import numpy as np\n'), ((1200, 58, 1200, 77), 'numpy.log', 'np.log', ({(1200, 65, 1200, 76): '(20.0 / 10.0)'}, {}), '(20.0 / 10.0)', True, 'import numpy as np\n'), ((380, 22, 387, 17), 'numpy.array', 'np.array', ({(381, 20, 386, 21): '[1.0, resids[t - 1] ** 2.0, resids[t - 1] ** 2.0 * (resids[t - 1] < 0),\n    sigma2[t - 1]]'}, {}), '([1.0, resids[t - 1] ** 2.0, resids[t - 1] ** 2.0 * (resids[t - 1] <\n    0), sigma2[t - 1]])', True, 'import numpy as np\n'), ((782, 36, 782, 48), 'scipy.special.gamma', 'gamma', ({(782, 42, 782, 47): '(j + 1)'}, {}), '(j + 1)', False, 'from scipy.special import gamma\n'), ((782, 51, 782, 61), 'scipy.special.gamma', 'gamma', ({(782, 57, 782, 60): '(0.6)'}, {}), '(0.6)', False, 'from scipy.special import gamma\n'), ((808, 36, 808, 48), 'scipy.special.gamma', 'gamma', ({(808, 42, 808, 47): '(j + 1)'}, {}), '(j + 1)', False, 'from scipy.special import gamma\n'), ((808, 51, 808, 61), 'scipy.special.gamma', 'gamma', ({(808, 57, 808, 60): '(0.6)'}, {}), '(0.6)', False, 'from scipy.special import gamma\n'), ((377, 20, 377, 71), 'numpy.array', 'np.array', ({(377, 29, 377, 70): '[1.0, backcast, 0.5 * backcast, backcast]'}, {}), '([1.0, backcast, 0.5 * backcast, backcast])', True, 'import numpy as np\n'), ((713, 43, 713, 65), 'numpy.sqrt', 'np.sqrt', ({(713, 51, 713, 64): 'sigma2[t - 1]'}, {}), '(sigma2[t - 1])', True, 'import numpy as np\n'), ((714, 48, 714, 64), 'numpy.abs', 'np.abs', ({(714, 55, 714, 63): 'stdresid'}, {}), '(stdresid)', True, 'import numpy as np\n')]