arch.bootstrap.StationaryBootstrap

class arch.bootstrap.StationaryBootstrap(block_size: int, *args: ndarray | DataFrame | Series, seed: int | Generator | RandomState | None = None, **kwargs: ndarray | DataFrame | Series)[source]

Politis and Romano (1994) bootstrap with expon distributed block sizes.

Parameters:
block_size: int

Average size of block to use. Can be any number that is at least 1, for example, the value estimated by optimal_block_length.

*args: ndarray | DataFrame | Series

Positional arguments to bootstrap. Each must have at least one row.

seed: int | Generator | RandomState | None = None

Seed to use to ensure reproducible results. If an int, it must be non-negative and is passed to np.random.default_rng. If None, a fresh Generator is constructed with system-provided entropy.

**kwargs: ndarray | DataFrame | Series

Keyword arguments to bootstrap. Each must have at least one row.

data

Two-element tuple with the pos_data in the first position and kw_data in the second (pos_data, kw_data).

Type:

tuple

pos_data

Tuple containing the positional arguments (in the order entered).

Type:

tuple

kw_data

Dictionary containing the keyword arguments.

Type:

dict

Raises:
  • TypeError – If an input is not an ndarray, Series or DataFrame, block_size is not an int or a float, or seed is not None, a non-negative int, a Generator or a RandomState.

  • ValueError – If there are no inputs, an input has no rows, the inputs do not have the same number of rows, block_size is less than 1 or not finite, seed is a negative int, or a keyword argument has the name of an attribute or method of the bootstrap.

See also

arch.bootstrap.optimal_block_length

Optimal block length estimation.

arch.bootstrap.CircularBlockBootstrap

Circular (wrap-around) bootstrap.

Notes

Supports numpy arrays and pandas Series and DataFrames. Data returned has the same type as the input data.

The data are used as given. They are not converted to float64 and are not checked for NaN or inf, since the function that is bootstrapped decides how to treat them (for example, using np.nanmean).

Data entered using keyword arguments is directly accessible as an attribute.

To ensure a reproducible bootstrap, you must pass the seed keyword argument when the bootstrap is created. See the example below. Note that seed is a reserved keyword and any variable passed using this keyword must be an integer, a Generator or a RandomState.

Examples

Data can be accessed in a number of ways. Positional data is retained in the same order as it was entered when the bootstrap was initialized. Keyword data is available both as an attribute or using a dictionary syntax on kw_data.

>>> from arch.bootstrap import StationaryBootstrap
>>> from numpy.random import standard_normal
>>> y = standard_normal((500, 1))
>>> x = standard_normal((500,2))
>>> z = standard_normal(500)
>>> bs = StationaryBootstrap(12, x, y=y, z=z)
>>> for data in bs.bootstrap(100):
...     bs_x = data[0][0]
...     bs_y = data[1]['y']
...     bs_z = bs.z

Set the seed if reproducibility is required

>>> from numpy.random import default_rng
>>> gen = default_rng(1234)
>>> bs = StationaryBootstrap(12, x, y=y, z=z, seed=gen)

Methods

apply(func[, reps, extra_kwargs])

Apply a function to bootstrap replicated data.

bootstrap(reps)

Iterate over the bootstrap replications.

clone(*args[, seed])

Clone the bootstrap using different data with a fresh prng.

conf_int(func[, reps, method, size, tail, ...])

Compute confidence intervals using the bootstrap.

cov(func[, reps, recenter, extra_kwargs])

Compute parameter covariance using bootstrap.

reset([use_seed])

Reset the bootstrap to its initial state.

update_indices()

Update indices for the next iteration of the bootstrap.

var(func[, reps, recenter, extra_kwargs])

Compute parameter variance using bootstrap.

Properties

block_size

The block size of the bootstrap.

generator

Set or get the instance PRNG.

index

The current index of the bootstrap.

state

Set or get the generator's state.