Beispiel #1
0
                if (t - j - 1) >= 0:
                    sigma2[t] += param * resids[t - j - 1] * resids[t - j - 1]
                else:
                    sigma2[t] += param * backcast
        if sigma2[t] < var_bounds[t, 0]:
            sigma2[t] = var_bounds[t, 0]
        elif sigma2[t] > var_bounds[t, 1]:
            if not np.isinf(sigma2[t]):
                sigma2[t] = var_bounds[t, 1] + log(sigma2[t] / var_bounds[t, 1])
            else:
                sigma2[t] = var_bounds[t, 1] + 1000

    return sigma2


harch_recursion = jit(harch_recursion_python)


def arch_recursion_python(parameters, resids, sigma2, p, nobs, backcast,
                          var_bounds):
    """
    Parameters
    ----------
    parameters : array
        Model parameters
    resids : array
        Residuals to use in the recursion
    sigma2 : array
        Conditional variances with same shape as resids
    p : int
        Number of lags in ARCH model
Beispiel #2
0
LNSIGMA_MAX = np.log(np.finfo(np.double).max) - 0.1


def bounds_check_python(sigma2: float, var_bounds: NDArray) -> float:
    if sigma2 < var_bounds[0]:
        sigma2 = var_bounds[0]
    elif sigma2 > var_bounds[1]:
        if not np.isinf(sigma2):
            sigma2 = var_bounds[1] + np.log(sigma2 / var_bounds[1])
        else:
            sigma2 = var_bounds[1] + 1000
    return sigma2


bounds_check = jit(bounds_check_python, nopython=True)


def harch_recursion_python(
    parameters: NDArray,
    resids: NDArray,
    sigma2: NDArray,
    lags: NDArray,
    nobs: int,
    backcast: float,
    var_bounds: NDArray,
) -> NDArray:
    """
    Parameters
    ----------
    parameters : ndarray
Beispiel #3
0
LNSIGMA_MAX = float(np.log(np.finfo(np.double).max) - 0.1)
SQRT2_OV_PI = 0.79788456080286541  # E[abs(e)], e~N(0,1)


def bounds_check_python(sigma2: float, var_bounds: NDArray) -> float:
    if sigma2 < var_bounds[0]:
        sigma2 = var_bounds[0]
    elif sigma2 > var_bounds[1]:
        if not np.isinf(sigma2):
            sigma2 = var_bounds[1] + np.log(sigma2 / var_bounds[1])
        else:
            sigma2 = var_bounds[1] + 1000
    return sigma2


bounds_check = jit(bounds_check_python, nopython=True, inline="always")


def harch_core_python(
    t: int,
    parameters: NDArray,
    resids: NDArray,
    sigma2: NDArray,
    lags: NDArray,
    backcast: float,
    var_bounds: NDArray,
) -> float:
    sigma2[t] = parameters[0]
    for i in range(lags.shape[0]):
        param = parameters[i + 1] / lags[i]
        for j in range(lags[i]):
Beispiel #4
0
    """
    Generate indices for sampling from the stationary bootstrap.

    Parameters
    -------
    indices: ndarray
        Single-dimensional array containing draws from randint with the same
        size as the data in the range of [0,nobs).
    u : ndarray
        Single-dimensional Array of standard uniforms.
    p : float
        Probability that a new block is started in the stationary bootstrap.
        The multiplicative reciprocal of the window length.

    Returns
    -------
    ndarray
        Indices for an iteration of the stationary bootstrap.
    """
    num_items = indices.shape[0]
    for i in range(1, num_items):
        if u[i] > p:
            indices[i] = indices[i - 1] + 1
            if indices[i] == num_items:
                indices[i] = 0

    return indices


stationary_bootstrap_sample = jit(stationary_bootstrap_sample_python)
Beispiel #5
0
LNSIGMA_MAX = np.log(np.finfo(np.double).max) - .1


def bounds_check_python(sigma2, var_bounds):
    if sigma2 < var_bounds[0]:
        sigma2 = var_bounds[0]
    elif sigma2 > var_bounds[1]:
        if not np.isinf(sigma2):
            sigma2 = var_bounds[1] + np.log(sigma2 / var_bounds[1])
        else:
            sigma2 = var_bounds[1] + 1000
    return sigma2


bounds_check = jit(bounds_check_python, nopython=True)


def harch_recursion_python(parameters, resids, sigma2, lags, nobs, backcast,
                           var_bounds):
    """
    Parameters
    ----------
    parameters : ndarray
        Model parameters
    resids : ndarray
        Residuals to use in the recursion
    sigma2 : ndarray
        Conditional variances with same shape as resids
    lags : ndarray
        Lag lengths in the HARCH
Beispiel #6
0
    alpha = parameters[1]
    beta = parameters[2]
    theta = parameters[3]

    sigma2[0] = backcast

    for t in range(1, nobs):
        sigma2[t] = omega + \
                    alpha * (resids[t - 1] - theta * np.sqrt(sigma2[t - 1])) ** 2.0 + \
                    beta * sigma2[t - 1]
        sigma2[t] = bounds_check(sigma2[t], var_bounds[t])

    return sigma2


ngarch11_recursion = jit(ngarch11_recursion_python, nopython=True)


def fixedngarch11_recursion_python(parameters: NDArray, theta: float,
                                   resids: NDArray, sigma2: NDArray, nobs: int,
                                   backcast: float,
                                   var_bounds: NDArray) -> NDArray:
    """
    Compute variance recursion for FixedNGARCH(1,1) and related models
    Parameters
    ----------
    parameters : ndarray
        Model parameters
    theta : float
        Value of fixed theta in model.
    resids : ndarray
Beispiel #7
0
def stationary_bootstrap_sample_python(indices, u, p):
    """
    Parameters
    -------
    indices: array
        Array containing draws from randint with the same size as the data in
        the range of [0,nobs)
    u : array
        Array of standard uniforms
    p : float
        Probability that a new block is started in the stationary bootstrap.
        The multiplicative reciprocal of the window length

    Returns
    -------
    indices: array
        Indices for an iteration of the stationary bootstrap
    """
    num_items = indices.shape[0]
    for i in range(1, num_items):
        if u[i] > p:
            indices[i] = indices[i - 1] + 1
            if indices[i] == num_items:
                indices[i] = 0

    return indices


stationary_bootstrap_sample = jit(stationary_bootstrap_sample_python)