qis.bootstrap_data¶
- qis.bootstrap_data(data, bootstrap_type=BootstrapType.STATIONARY, bootstrap_output=BootstrapOutput.DF_TO_LIST_ARRAYS, num_samples=10, index_length=1000, block_size=30, min_block_size=1, seed=1, bootstrapped_indices=None)[source]¶
resample a series or panel with replacement, preserving the cross-section within each draw.
The whole row is resampled, not each column independently, so the contemporaneous correlation structure survives. To resample two aligned panels jointly - factor returns and residuals, say - draw the indices once with
generate_bootstrapped_indices()and pass them here asbootstrapped_indicesfor each panel.- Parameters:
data (Series | DataFrame) – observations to resample, rows are dates. A Series is resampled as a one-column panel under DF_TO_LIST_ARRAYS
bootstrap_type (BootstrapType) – resampling scheme; see
BootstrapTypebootstrap_output (BootstrapOutput) – shape of the result; see
BootstrapOutputnum_samples (int) – number of independent draws
index_length (int) – length of each draw, which need not equal the length of
datablock_size (int) – mean block length for STATIONARY, exact length for FIXED_BLOCK
min_block_size (int) – floor on the drawn block length under STATIONARY
seed (int) – seed for the numba random state
bootstrapped_indices (ndarray) – precomputed indices of shape
(index_length, number of draws). Given, every sampling argument above is ignored, includingnum_samples: the number of draws is the number of columns of this array. This is how paired resampling is done
- Returns:
a DataFrame of draws for SERIES_TO_DF, with columns
path_1,path_2, … on a RangeIndex, or a numba list of arrays of shape(index_length, number of columns)for DF_TO_LIST_ARRAYS- Raises:
ValueError – if supplied
bootstrapped_indicesfall outside[0, len(data.index)), or if SERIES_TO_DF is requested for a DataFrame- Return type:
List | DataFrame