qis.bootstrap_price_data¶
- qis.bootstrap_price_data(prices, bootstrap_type=BootstrapType.STATIONARY, bootstrap_output=BootstrapOutput.DF_TO_LIST_ARRAYS, num_samples=10, index_length=1000, block_size=20, min_block_size=1, is_log_returns=False, seed=1, bootstrapped_indices=None, init_to_end=True)[source]¶
resample price levels by resampling their returns and recompounding.
Prices are not resampled directly - a block of prices lifted from one part of the sample would jump at the joins. Returns are resampled and then compounded back into a path, so each draw is a continuous price series with the return distribution of the original.
Anchor convention: row 0 of every path is the anchor price itself, and row
kcompounds the anchor with the returns drawn at index rows1..k. The return drawn at index row 0 is not used, so a path ofindex_lengthlevels carriesindex_length - 1resampled returns. Passindex_length=K + 1forKresampled returns after the anchor.- Parameters:
prices (Series | DataFrame) – Price levels. A Series represents one asset; a DataFrame has one column per asset.
bootstrap_type (BootstrapType) – resampling scheme; see
BootstrapTypebootstrap_output (BootstrapOutput) – Shape of the result; see
BootstrapOutput. Series input supports either output mode;DF_TO_LIST_ARRAYSreturns one-column arrays for that case.num_samples (int) – number of independent draws
index_length (int) – length of each draw, anchor row included
block_size (int) – mean block length for STATIONARY, exact length for FIXED_BLOCK. 1 is IID
min_block_size (int) – floor on the drawn block length under STATIONARY
is_log_returns (bool) – resample log returns rather than arithmetic ones
seed (int) – seed for the numba random state
bootstrapped_indices (ndarray) – precomputed indices over the
len(prices.index) - 1return rows, which override the sampling arguments; the number of paths is then the number of columns of this array, whatevernum_samplessaysinit_to_end (bool) – Start each path from its input series’ last positive finite price, so ragged columns continue from their own terminal observation. False starts every path from the physical first row, so the draws are alternative histories
- Returns:
A DataFrame of paths for SERIES_TO_DF, or a list of arrays for DF_TO_LIST_ARRAYS.
- Return type: