arch.bootstrap.IIDBootstrap.apply

IIDBootstrap.apply(func: Callable[[...], ndarray | DataFrame | Series], reps: int = 1000, extra_kwargs: dict[str, Any] | None = None) → ndarray[tuple[int, ...], dtype[float64]][source]

Apply a function to bootstrap replicated data.

Parameters:
func: Callable[[...], ndarray | DataFrame | Series]

Function that computes parameter values. See Notes for requirements.

reps: int = 1000

Number of bootstrap replications. Must be at least 1.

extra_kwargs: dict[str, Any] | None = None

Extra keyword arguments to use when calling func. Must not conflict with keyword arguments used to initialize bootstrap.

Returns:

The reps by nparam array of computed function values where each row corresponds to a bootstrap iteration. The array is complex128 if func returns complex values and float64 otherwise.

Return type:

numpy.ndarray

Raises:
  • TypeError – If func is not callable, reps is not an int, or extra_kwargs is not a dict.

  • ValueError – If reps is less than 1, or extra_kwargs has a key that is the name of bootstrapped data.

Notes

When there are no extra keyword arguments, the function is called

func(*args, **kwargs)

where args and kwargs are the bootstrap version of the data provided when setting up the bootstrap. When extra keyword arguments are used, these are appended to kwargs before calling func. The function can return a scalar, a 0-dimensional array or a 1-dimensional array-like.

Examples

>>> import numpy as np
>>> x = np.random.randn(1000,2)
>>> from arch.bootstrap import IIDBootstrap
>>> bs = IIDBootstrap(x)
>>> def func(y):
...     return y.mean(0)
>>> results = bs.apply(func, 100)