https://github.com/bashtage/arch
Raw File
Tip revision: ff0b6a62cfac2e848f5e84656eab9989982cc433 authored by Kevin Sheppard on 02 March 2021, 17:30:49 UTC
Merge pull request #460 from bashtage/rls-4.17
Tip revision: ff0b6a6
_samplers_python.py
from arch.compat.numba import jit

from arch.typing import NDArray


def stationary_bootstrap_sample_python(
    indices: NDArray, u: NDArray, p: float
) -> NDArray:
    """
    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)
back to top