Fully Flexible Resampling

The Fully Flexible Resampling functionality is one of the core simulation methods. Although it is contained in a single class having only few methods, it is very powerful and capable of simulating high-frequency paths for very high-dimensional time series.

Fully Flexible Resampling was introduced in the Portfolio Construction and Risk Management book, which contains an in-depth description of the method. To fully understand the mathematics, it is helpful to see examples of the intermediate output. This can be found in the notebooks that are available as Investment Simulation examples.

See also the Time- and State-Dependent Resampling article for detailed mathematical proofs, showing that the procedure generates strictly stationary simulations.

class FullyFlexibleResampling(stationary_data, **kwargs)

Class for Fully Flexible Resampling.

Parameters:
  • stationary_data (Union[DataFrame, ndarray]) – Matrix with shape (T, I) containing a historical time-series for the stationary data.

  • kwargs – Options dictionary containing Entropy Pooling control parameters. See Entropy Pooling documentation.

Raises:

TypeError – If stationary_data is not a pd.DataFrame or np.ndarray.

compute_probabilities(state_variables, conditioning_values, half_life=None, details=False)

Method for computing state probability vectors.

Parameters:
  • state_variables (Union[DataFrame, ndarray]) – Matrix with shape (T, M) or (T,) containing the historical state variables.

  • conditioning_values (list[Union[list[float], str]]) – Conditioning values in a list of length M. Entries must be list of values for continuous variables or a string ‘discrete’ for discrete variables.

  • half_life (float) – Optional exponential decay half life for prior computations. Uniform by default.

  • details (bool) – Optional boolean for whether to return individual probabilities and weights when there are multiple state variables. Default: False.

Return type:

Union[Tuple[ndarray, ndarray], Tuple[ndarray, ndarray, ndarray, ndarray]]

Returns:

Posterior fully flexible probabilities and the corresponding state vector. Optionally the posterior fully flexible probabilities of the individual state variables and weights if there are multiple state variables and details=True.

Raises:
  • TypeError – If state_variables is not a pd.DataFrame or np.ndarray.

  • ValueError – If state_variables has more than 2 dimensions.

  • ValueError – If state_variables does not have T rows.

  • ValueError – If the length of conditioning_values does not equal the number of state variables.

  • ValueError – If the conditioning values specify an interval for which no observations of the corresponding state variable exists.

  • ValueError – If a state variable is marked as ‘discrete’ in conditioning_values, but is not integer valued.

  • ValueError – If conditioning_values contains elements that are not of type list or the string ‘discrete’.

simulate(S, H, probabilities, state_vector, initial_state=None, B=None)

Method for simulating data.

Parameters:
  • S (int) – Number of desired simulations.

  • H (int) – Projection horizon (number of steps).

  • probabilities (ndarray) – Probabilities matrix with shape (T, num_states).

  • state_vector (ndarray) – Vector with shape (T,) containing the states.

  • initial_state (Union[int, list, ndarray]) – Integer containing the initial state if the same initial state is to be used in all simulations. List of length num_states or array of shape (num_states,) consisting of positive elements summing to one in case the initial state varies. If none is given the last state of state_vector is used in all simulations.

  • B (int) – Block size to be used in moving block bootstrap. Default: 1.

Return type:

ndarray

Returns:

Matrix with simulated data and shape (S, I, H).

Raises:
  • ValueError – If probabilities does not have shape (T, num_states).

  • ValueError – If any column in probabilities does not consist of positive elements summing to 1.

  • ValueError – If states_vector does not have shape (T,).

  • ValueError – If the states in state_vector are not [0, 1, …, num_states].

  • TypeError – If initial_state is not an integer, list, or array.

  • ValueError – If initial_state is an integer which is not in [0, num_states).

  • ValueError – If initial_state is an array with more than one dimension.

  • ValueError – If initial_state is a list or array which does not have length num_states or does not consist of non-negative elements summing to one.

  • TypeError – If B is not an int.

  • ValueError – If B does not divide H.

  • ValueError – If B is not in the interval [1, T]

transition_matrix(probabilities, states_vector)

Function for computing the transition matrix of a Markov chain.

Parameters:
  • probabilities (ndarray) – Scenario probability matrix with shape (T, num_states).

  • states_vector (ndarray) – Vector with shape (T,) containing the states.

Return type:

ndarray

Returns:

Transition matrix with shape (num_states, num_states).

Raises:
  • ValueError – If probabilities does not have shape (T, num_states).

  • ValueError – If any column in probabilities does not consist of non-negative elements summing to 1.

  • ValueError – If states_vector does not have shape (T,).

  • ValueError – If the states in state_vector are not [0, 1, …, num_states].