Time-series Bootstraps

Bootstraps for time-series data come in a variety of forms. The three contained in this package are the stationary bootstrap (StationaryBootstrap), which uses blocks with an exponentially distributed lengths, the circular block bootstrap (CircularBlockBootstrap), which uses fixed length blocks, and the moving block bootstrap which also uses fixed length blocks (MovingBlockBootstrap). The moving block bootstrap does not wrap around and so observations near the start or end of the series will be systematically under-sampled. It is not recommended for this reason.

The Stationary Bootstrap

class arch.bootstrap.StationaryBootstrap(block_size, *args, **kwargs)[source]

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

Parameters:
  • block_size (int) – Average size of block to use
  • args – Positional arguments to bootstrap
  • kwargs – Keyword arguments to bootstrap
index

ndarray – The current index of the bootstrap

data

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

pos_data

tuple – Tuple containing the positional arguments (in the order entered)

kw_data

dict – Dictionary containing the keyword arguments

random_state

RandomState – RandomState instance used by bootstrap

Notes

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

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

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
apply(func, reps=1000, extra_kwargs=None)

Applies a function to bootstrap replicated data

Parameters:
  • func (callable) – Function the computes parameter values. See Notes for requirements
  • reps (int, optional) – Number of bootstrap replications
  • extra_kwargs (dict, optional) – Extra keyword arguments to use when calling func. Must not conflict with keyword arguments used to initialize bootstrap
Returns:

results – reps by nparam array of computed function values where each row corresponds to a bootstrap iteration

Return type:

ndarray

Notes

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

func(params, *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

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)
bootstrap(reps)

Iterator for use when bootstrapping

Parameters:reps (int) – Number of bootstrap replications
Returns:gen – Generator to iterate over in bootstrap calculations
Return type:generator

Example

The key steps are problem dependent and so this example shows the use as an iterator that does not produce any output

>>> from arch.bootstrap import IIDBootstrap
>>> import numpy as np
>>> bs = IIDBootstrap(np.arange(100), x=np.random.randn(100))
>>> for posdata, kwdata in bs.bootstrap(1000):
...     # Do something with the positional data and/or keyword data
...     pass

Note

Note this is a generic example and so the class used should be the name of the required bootstrap

Notes

The iterator returns a tuple containing the data entered in positional arguments as a tuple and the data entered using keywords as a dictionary

conf_int(func, reps=1000, method='basic', size=0.95, tail='two', extra_kwargs=None, reuse=False, sampling='nonparametric', std_err_func=None, studentize_reps=1000)
Parameters:
  • func (callable) – Function the computes parameter values. See Notes for requirements
  • reps (int, optional) – Number of bootstrap replications
  • method (string, optional) – One of ‘basic’, ‘percentile’, ‘studentized’, ‘norm’ (identical to ‘var’, ‘cov’), ‘bc’ (identical to ‘debiased’, ‘bias-corrected’), or ‘bca’
  • size (float, optional) – Coverage of confidence interval
  • tail (string, optional) – One of ‘two’, ‘upper’ or ‘lower’.
  • reuse (bool, optional) – Flag indicating whether to reuse previously computed bootstrap results. This allows alternative methods to be compared without rerunning the bootstrap simulation. Reuse is ignored if reps is not the same across multiple runs, func changes across calls, or method is ‘studentized’.
  • sampling (string, optional) – Type of sampling to use: ‘nonparametric’, ‘semi-parametric’ (or ‘semi’) or ‘parametric’. The default is ‘nonparametric’. See notes about the changes to func required when using ‘semi’ or ‘parametric’.
  • extra_kwargs (dict, optional) – Extra keyword arguments to use when calling func and std_err_func, when appropriate
  • std_err_func (callable, optional) – Function to use when standardizing estimated parameters when using the studentized bootstrap. Providing an analytical function eliminates the need for a nested bootstrap
  • studentize_reps (int, optional) – Number of bootstraps to use in the inner bootstrap when using the studentized bootstrap. Ignored when std_err_func is provided
Returns:

intervals – Computed confidence interval. Row 0 contains the lower bounds, and row 1 contains the upper bounds. Each column corresponds to a parameter. When tail is ‘lower’, all upper bounds are inf. Similarly, ‘upper’ sets all lower bounds to -inf.

Return type:

2-d array

Examples

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

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 standard error function, if provided, must return a vector of parameter standard errors and is called

std_err_func(params, *args, **kwargs)

where params is the vector of estimated parameters using the same bootstrap data as in args and kwargs.

The bootstraps are:

  • ‘basic’ - Basic confidence using the estimated parameter and difference between the estimated parameter and the bootstrap parameters
  • ‘percentile’ - Direct use of bootstrap percentiles
  • ‘norm’ - Makes use of normal approximation and bootstrap covariance estimator
  • ‘studentized’ - Uses either a standard error function or a nested bootstrap to estimate percentiles and the bootstrap covariance for scale
  • ‘bc’ - Bias corrected using estimate bootstrap bias correction
  • ‘bca’ - Bias corrected and accelerated, adding acceleration parameter to ‘bc’ method
cov(func, reps=1000, recenter=True, extra_kwargs=None)

Compute parameter covariance using bootstrap

Parameters:
  • func (callable) – Callable function that returns the statistic of interest as a 1-d array
  • reps (int, optional) – Number of bootstrap replications
  • recenter (bool, optional) – Whether to center the bootstrap variance estimator on the average of the bootstrap samples (True) or to center on the original sample estimate (False). Default is True.
  • extra_kwargs (dict, optional) – Dictionary of extra keyword arguments to pass to func
Returns:

cov – Bootstrap covariance estimator

Return type:

ndarray

Notes

func must have the signature

func(params, *args, **kwargs)

where params are a 1-dimensional array, and *args and **kwargs are data used in the the bootstrap. The first argument, params, will be none when called using the original data, and will contain the estimate computed using the original data in bootstrap replications. This parameter is passed to allow parametric bootstrap simulation.

Example

Bootstrap covariance of the mean

>>> from arch.bootstrap import IIDBootstrap
>>> import numpy as np
>>> def func(x):
...     return x.mean(axis=0)
>>> y = np.random.randn(1000, 3)
>>> bs = IIDBootstrap(y)
>>> cov = bs.cov(func, 1000)

Bootstrap covariance using a function that takes additional input

>>> def func(x, stat='mean'):
...     if stat=='mean':
...         return x.mean(axis=0)
...     elif stat=='var':
...         return x.var(axis=0)
>>> cov = bs.cov(func, 1000, extra_kwargs={'stat':'var'})

Note

Note this is a generic example and so the class used should be the name of the required bootstrap

get_state()

Gets the state of the bootstrap’s random number generator

Returns:state – Array containing the state
Return type:RandomState state vector
reset(use_seed=True)

Resets the bootstrap to either its initial state or the last seed.

Parameters:use_seed (bool, optional) – Flag indicating whether to use the last seed if provided. If False or if no seed has been set, the bootstrap will be reset to the initial state. Default is True
seed(value)

Seeds the bootstrap’s random number generator

Parameters:value (int) – Integer to use as the seed
set_state(state)

Sets the state of the bootstrap’s random number generator

Parameters:state (RandomState state vector) – Array containing the state
var(func, reps=1000, recenter=True, extra_kwargs=None)

Compute parameter variance using bootstrap

Parameters:
  • func (callable) – Callable function that returns the statistic of interest as a 1-d array
  • reps (int, optional) – Number of bootstrap replications
  • recenter (bool, optional) – Whether to center the bootstrap variance estimator on the average of the bootstrap samples (True) or to center on the original sample estimate (False). Default is True.
  • extra_kwargs (dict, optional) – Dictionary of extra keyword arguments to pass to func
Returns:

var – Bootstrap variance estimator

Return type:

ndarray

Notes

func must have the signature

func(params, *args, **kwargs)

where params are a 1-dimensional array, and *args and **kwargs are data used in the the bootstrap. The first argument, params, will be none when called using the original data, and will contain the estimate computed using the original data in bootstrap replications. This parameter is passed to allow parametric bootstrap simulation.

Example

Bootstrap covariance of the mean

>>> from arch.bootstrap import IIDBootstrap
>>> import numpy as np
>>> def func(x):
...     return x.mean(axis=0)
>>> y = np.random.randn(1000, 3)
>>> bs = IIDBootstrap(y)
>>> variances = bs.var(func, 1000)

Bootstrap covariance using a function that takes additional input

>>> def func(x, stat='mean'):
...     if stat=='mean':
...         return x.mean(axis=0)
...     elif stat=='var':
...         return x.var(axis=0)
>>> variances = bs.var(func, 1000, extra_kwargs={'stat': 'var'})

Note

Note this is a generic example and so the class used should be the name of the required bootstrap

The Circular Block Bootstrap

class arch.bootstrap.CircularBlockBootstrap(block_size, *args, **kwargs)[source]

Bootstrap based on blocks of the same length with end-to-start wrap around

Parameters:
  • block_size (int) – Size of block to use
  • args – Positional arguments to bootstrap
  • kwargs – Keyword arguments to bootstrap
index

ndarray – The current index of the bootstrap

data

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

pos_data

tuple – Tuple containing the positional arguments (in the order entered)

kw_data

dict – Dictionary containing the keyword arguments

random_state

RandomState – RandomState instance used by bootstrap

Notes

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

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

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 CircularBlockBootstrap
>>> from numpy.random import standard_normal
>>> y = standard_normal((500, 1))
>>> x = standard_normal((500, 2))
>>> z = standard_normal(500)
>>> bs = CircularBlockBootstrap(17, 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
apply(func, reps=1000, extra_kwargs=None)

Applies a function to bootstrap replicated data

Parameters:
  • func (callable) – Function the computes parameter values. See Notes for requirements
  • reps (int, optional) – Number of bootstrap replications
  • extra_kwargs (dict, optional) – Extra keyword arguments to use when calling func. Must not conflict with keyword arguments used to initialize bootstrap
Returns:

results – reps by nparam array of computed function values where each row corresponds to a bootstrap iteration

Return type:

ndarray

Notes

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

func(params, *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

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)
bootstrap(reps)

Iterator for use when bootstrapping

Parameters:reps (int) – Number of bootstrap replications
Returns:gen – Generator to iterate over in bootstrap calculations
Return type:generator

Example

The key steps are problem dependent and so this example shows the use as an iterator that does not produce any output

>>> from arch.bootstrap import IIDBootstrap
>>> import numpy as np
>>> bs = IIDBootstrap(np.arange(100), x=np.random.randn(100))
>>> for posdata, kwdata in bs.bootstrap(1000):
...     # Do something with the positional data and/or keyword data
...     pass

Note

Note this is a generic example and so the class used should be the name of the required bootstrap

Notes

The iterator returns a tuple containing the data entered in positional arguments as a tuple and the data entered using keywords as a dictionary

conf_int(func, reps=1000, method='basic', size=0.95, tail='two', extra_kwargs=None, reuse=False, sampling='nonparametric', std_err_func=None, studentize_reps=1000)
Parameters:
  • func (callable) – Function the computes parameter values. See Notes for requirements
  • reps (int, optional) – Number of bootstrap replications
  • method (string, optional) – One of ‘basic’, ‘percentile’, ‘studentized’, ‘norm’ (identical to ‘var’, ‘cov’), ‘bc’ (identical to ‘debiased’, ‘bias-corrected’), or ‘bca’
  • size (float, optional) – Coverage of confidence interval
  • tail (string, optional) – One of ‘two’, ‘upper’ or ‘lower’.
  • reuse (bool, optional) – Flag indicating whether to reuse previously computed bootstrap results. This allows alternative methods to be compared without rerunning the bootstrap simulation. Reuse is ignored if reps is not the same across multiple runs, func changes across calls, or method is ‘studentized’.
  • sampling (string, optional) – Type of sampling to use: ‘nonparametric’, ‘semi-parametric’ (or ‘semi’) or ‘parametric’. The default is ‘nonparametric’. See notes about the changes to func required when using ‘semi’ or ‘parametric’.
  • extra_kwargs (dict, optional) – Extra keyword arguments to use when calling func and std_err_func, when appropriate
  • std_err_func (callable, optional) – Function to use when standardizing estimated parameters when using the studentized bootstrap. Providing an analytical function eliminates the need for a nested bootstrap
  • studentize_reps (int, optional) – Number of bootstraps to use in the inner bootstrap when using the studentized bootstrap. Ignored when std_err_func is provided
Returns:

intervals – Computed confidence interval. Row 0 contains the lower bounds, and row 1 contains the upper bounds. Each column corresponds to a parameter. When tail is ‘lower’, all upper bounds are inf. Similarly, ‘upper’ sets all lower bounds to -inf.

Return type:

2-d array

Examples

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

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 standard error function, if provided, must return a vector of parameter standard errors and is called

std_err_func(params, *args, **kwargs)

where params is the vector of estimated parameters using the same bootstrap data as in args and kwargs.

The bootstraps are:

  • ‘basic’ - Basic confidence using the estimated parameter and difference between the estimated parameter and the bootstrap parameters
  • ‘percentile’ - Direct use of bootstrap percentiles
  • ‘norm’ - Makes use of normal approximation and bootstrap covariance estimator
  • ‘studentized’ - Uses either a standard error function or a nested bootstrap to estimate percentiles and the bootstrap covariance for scale
  • ‘bc’ - Bias corrected using estimate bootstrap bias correction
  • ‘bca’ - Bias corrected and accelerated, adding acceleration parameter to ‘bc’ method
cov(func, reps=1000, recenter=True, extra_kwargs=None)

Compute parameter covariance using bootstrap

Parameters:
  • func (callable) – Callable function that returns the statistic of interest as a 1-d array
  • reps (int, optional) – Number of bootstrap replications
  • recenter (bool, optional) – Whether to center the bootstrap variance estimator on the average of the bootstrap samples (True) or to center on the original sample estimate (False). Default is True.
  • extra_kwargs (dict, optional) – Dictionary of extra keyword arguments to pass to func
Returns:

cov – Bootstrap covariance estimator

Return type:

ndarray

Notes

func must have the signature

func(params, *args, **kwargs)

where params are a 1-dimensional array, and *args and **kwargs are data used in the the bootstrap. The first argument, params, will be none when called using the original data, and will contain the estimate computed using the original data in bootstrap replications. This parameter is passed to allow parametric bootstrap simulation.

Example

Bootstrap covariance of the mean

>>> from arch.bootstrap import IIDBootstrap
>>> import numpy as np
>>> def func(x):
...     return x.mean(axis=0)
>>> y = np.random.randn(1000, 3)
>>> bs = IIDBootstrap(y)
>>> cov = bs.cov(func, 1000)

Bootstrap covariance using a function that takes additional input

>>> def func(x, stat='mean'):
...     if stat=='mean':
...         return x.mean(axis=0)
...     elif stat=='var':
...         return x.var(axis=0)
>>> cov = bs.cov(func, 1000, extra_kwargs={'stat':'var'})

Note

Note this is a generic example and so the class used should be the name of the required bootstrap

get_state()

Gets the state of the bootstrap’s random number generator

Returns:state – Array containing the state
Return type:RandomState state vector
reset(use_seed=True)

Resets the bootstrap to either its initial state or the last seed.

Parameters:use_seed (bool, optional) – Flag indicating whether to use the last seed if provided. If False or if no seed has been set, the bootstrap will be reset to the initial state. Default is True
seed(value)

Seeds the bootstrap’s random number generator

Parameters:value (int) – Integer to use as the seed
set_state(state)

Sets the state of the bootstrap’s random number generator

Parameters:state (RandomState state vector) – Array containing the state
var(func, reps=1000, recenter=True, extra_kwargs=None)

Compute parameter variance using bootstrap

Parameters:
  • func (callable) – Callable function that returns the statistic of interest as a 1-d array
  • reps (int, optional) – Number of bootstrap replications
  • recenter (bool, optional) – Whether to center the bootstrap variance estimator on the average of the bootstrap samples (True) or to center on the original sample estimate (False). Default is True.
  • extra_kwargs (dict, optional) – Dictionary of extra keyword arguments to pass to func
Returns:

var – Bootstrap variance estimator

Return type:

ndarray

Notes

func must have the signature

func(params, *args, **kwargs)

where params are a 1-dimensional array, and *args and **kwargs are data used in the the bootstrap. The first argument, params, will be none when called using the original data, and will contain the estimate computed using the original data in bootstrap replications. This parameter is passed to allow parametric bootstrap simulation.

Example

Bootstrap covariance of the mean

>>> from arch.bootstrap import IIDBootstrap
>>> import numpy as np
>>> def func(x):
...     return x.mean(axis=0)
>>> y = np.random.randn(1000, 3)
>>> bs = IIDBootstrap(y)
>>> variances = bs.var(func, 1000)

Bootstrap covariance using a function that takes additional input

>>> def func(x, stat='mean'):
...     if stat=='mean':
...         return x.mean(axis=0)
...     elif stat=='var':
...         return x.var(axis=0)
>>> variances = bs.var(func, 1000, extra_kwargs={'stat': 'var'})

Note

Note this is a generic example and so the class used should be the name of the required bootstrap

The Moving Block Bootstrap

class arch.bootstrap.MovingBlockBootstrap(block_size, *args, **kwargs)[source]

Bootstrap based on blocks of the same length without wrap around

Parameters:
  • block_size (int) – Size of block to use
  • args – Positional arguments to bootstrap
  • kwargs – Keyword arguments to bootstrap
index

ndarray – The current index of the bootstrap

data

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

pos_data

tuple – Tuple containing the positional arguments (in the order entered)

kw_data

dict – Dictionary containing the keyword arguments

random_state

RandomState – RandomState instance used by bootstrap

Notes

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

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

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 MovingBlockBootstrap
>>> from numpy.random import standard_normal
>>> y = standard_normal((500, 1))
>>> x = standard_normal((500,2))
>>> z = standard_normal(500)
>>> bs = MovingBlockBootstrap(7, 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
apply(func, reps=1000, extra_kwargs=None)

Applies a function to bootstrap replicated data

Parameters:
  • func (callable) – Function the computes parameter values. See Notes for requirements
  • reps (int, optional) – Number of bootstrap replications
  • extra_kwargs (dict, optional) – Extra keyword arguments to use when calling func. Must not conflict with keyword arguments used to initialize bootstrap
Returns:

results – reps by nparam array of computed function values where each row corresponds to a bootstrap iteration

Return type:

ndarray

Notes

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

func(params, *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

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)
bootstrap(reps)

Iterator for use when bootstrapping

Parameters:reps (int) – Number of bootstrap replications
Returns:gen – Generator to iterate over in bootstrap calculations
Return type:generator

Example

The key steps are problem dependent and so this example shows the use as an iterator that does not produce any output

>>> from arch.bootstrap import IIDBootstrap
>>> import numpy as np
>>> bs = IIDBootstrap(np.arange(100), x=np.random.randn(100))
>>> for posdata, kwdata in bs.bootstrap(1000):
...     # Do something with the positional data and/or keyword data
...     pass

Note

Note this is a generic example and so the class used should be the name of the required bootstrap

Notes

The iterator returns a tuple containing the data entered in positional arguments as a tuple and the data entered using keywords as a dictionary

conf_int(func, reps=1000, method='basic', size=0.95, tail='two', extra_kwargs=None, reuse=False, sampling='nonparametric', std_err_func=None, studentize_reps=1000)
Parameters:
  • func (callable) – Function the computes parameter values. See Notes for requirements
  • reps (int, optional) – Number of bootstrap replications
  • method (string, optional) – One of ‘basic’, ‘percentile’, ‘studentized’, ‘norm’ (identical to ‘var’, ‘cov’), ‘bc’ (identical to ‘debiased’, ‘bias-corrected’), or ‘bca’
  • size (float, optional) – Coverage of confidence interval
  • tail (string, optional) – One of ‘two’, ‘upper’ or ‘lower’.
  • reuse (bool, optional) – Flag indicating whether to reuse previously computed bootstrap results. This allows alternative methods to be compared without rerunning the bootstrap simulation. Reuse is ignored if reps is not the same across multiple runs, func changes across calls, or method is ‘studentized’.
  • sampling (string, optional) – Type of sampling to use: ‘nonparametric’, ‘semi-parametric’ (or ‘semi’) or ‘parametric’. The default is ‘nonparametric’. See notes about the changes to func required when using ‘semi’ or ‘parametric’.
  • extra_kwargs (dict, optional) – Extra keyword arguments to use when calling func and std_err_func, when appropriate
  • std_err_func (callable, optional) – Function to use when standardizing estimated parameters when using the studentized bootstrap. Providing an analytical function eliminates the need for a nested bootstrap
  • studentize_reps (int, optional) – Number of bootstraps to use in the inner bootstrap when using the studentized bootstrap. Ignored when std_err_func is provided
Returns:

intervals – Computed confidence interval. Row 0 contains the lower bounds, and row 1 contains the upper bounds. Each column corresponds to a parameter. When tail is ‘lower’, all upper bounds are inf. Similarly, ‘upper’ sets all lower bounds to -inf.

Return type:

2-d array

Examples

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

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 standard error function, if provided, must return a vector of parameter standard errors and is called

std_err_func(params, *args, **kwargs)

where params is the vector of estimated parameters using the same bootstrap data as in args and kwargs.

The bootstraps are:

  • ‘basic’ - Basic confidence using the estimated parameter and difference between the estimated parameter and the bootstrap parameters
  • ‘percentile’ - Direct use of bootstrap percentiles
  • ‘norm’ - Makes use of normal approximation and bootstrap covariance estimator
  • ‘studentized’ - Uses either a standard error function or a nested bootstrap to estimate percentiles and the bootstrap covariance for scale
  • ‘bc’ - Bias corrected using estimate bootstrap bias correction
  • ‘bca’ - Bias corrected and accelerated, adding acceleration parameter to ‘bc’ method
cov(func, reps=1000, recenter=True, extra_kwargs=None)

Compute parameter covariance using bootstrap

Parameters:
  • func (callable) – Callable function that returns the statistic of interest as a 1-d array
  • reps (int, optional) – Number of bootstrap replications
  • recenter (bool, optional) – Whether to center the bootstrap variance estimator on the average of the bootstrap samples (True) or to center on the original sample estimate (False). Default is True.
  • extra_kwargs (dict, optional) – Dictionary of extra keyword arguments to pass to func
Returns:

cov – Bootstrap covariance estimator

Return type:

ndarray

Notes

func must have the signature

func(params, *args, **kwargs)

where params are a 1-dimensional array, and *args and **kwargs are data used in the the bootstrap. The first argument, params, will be none when called using the original data, and will contain the estimate computed using the original data in bootstrap replications. This parameter is passed to allow parametric bootstrap simulation.

Example

Bootstrap covariance of the mean

>>> from arch.bootstrap import IIDBootstrap
>>> import numpy as np
>>> def func(x):
...     return x.mean(axis=0)
>>> y = np.random.randn(1000, 3)
>>> bs = IIDBootstrap(y)
>>> cov = bs.cov(func, 1000)

Bootstrap covariance using a function that takes additional input

>>> def func(x, stat='mean'):
...     if stat=='mean':
...         return x.mean(axis=0)
...     elif stat=='var':
...         return x.var(axis=0)
>>> cov = bs.cov(func, 1000, extra_kwargs={'stat':'var'})

Note

Note this is a generic example and so the class used should be the name of the required bootstrap

get_state()

Gets the state of the bootstrap’s random number generator

Returns:state – Array containing the state
Return type:RandomState state vector
reset(use_seed=True)

Resets the bootstrap to either its initial state or the last seed.

Parameters:use_seed (bool, optional) – Flag indicating whether to use the last seed if provided. If False or if no seed has been set, the bootstrap will be reset to the initial state. Default is True
seed(value)

Seeds the bootstrap’s random number generator

Parameters:value (int) – Integer to use as the seed
set_state(state)

Sets the state of the bootstrap’s random number generator

Parameters:state (RandomState state vector) – Array containing the state
var(func, reps=1000, recenter=True, extra_kwargs=None)

Compute parameter variance using bootstrap

Parameters:
  • func (callable) – Callable function that returns the statistic of interest as a 1-d array
  • reps (int, optional) – Number of bootstrap replications
  • recenter (bool, optional) – Whether to center the bootstrap variance estimator on the average of the bootstrap samples (True) or to center on the original sample estimate (False). Default is True.
  • extra_kwargs (dict, optional) – Dictionary of extra keyword arguments to pass to func
Returns:

var – Bootstrap variance estimator

Return type:

ndarray

Notes

func must have the signature

func(params, *args, **kwargs)

where params are a 1-dimensional array, and *args and **kwargs are data used in the the bootstrap. The first argument, params, will be none when called using the original data, and will contain the estimate computed using the original data in bootstrap replications. This parameter is passed to allow parametric bootstrap simulation.

Example

Bootstrap covariance of the mean

>>> from arch.bootstrap import IIDBootstrap
>>> import numpy as np
>>> def func(x):
...     return x.mean(axis=0)
>>> y = np.random.randn(1000, 3)
>>> bs = IIDBootstrap(y)
>>> variances = bs.var(func, 1000)

Bootstrap covariance using a function that takes additional input

>>> def func(x, stat='mean'):
...     if stat=='mean':
...         return x.mean(axis=0)
...     elif stat=='var':
...         return x.var(axis=0)
>>> variances = bs.var(func, 1000, extra_kwargs={'stat': 'var'})

Note

Note this is a generic example and so the class used should be the name of the required bootstrap