Learn R Programming

SWIM (version 1.0.0)

SWIM: SWIM: A Package for Sensitivity Analysis

Description

The SWIM package provides weights on simulated scenarios from a stochastic model, such that a stressed model component (random variable) fulfil given probabilistic constraints (e.g. specified values for risk measures), under the new scenario weights. Scenario weights are selected by constrained minimisation of the relative entropy or Wasserstein distance to the baseline model.

Arguments

Stresses for Relative Entropy Minimization

Scenario weights for the following stresses are provided:

stress calls one of the functions below by using type
stress_VaR for stressing the VaR (type = "VaR")
stress_VaR_ES for stressing the VaR and ES jointly (type = "VaR ES")
stress_mean for stressing means (type = "mean")
stress_mean_sd for stressing means and standard deviations (type = "mean std")
stress_moment for stressing moments (type = "moment")
stress_prob for stressing the probabilities of intervals (type = "prob")
stress_user for user defined scenario weights (type = "user")

Stresses for Wasserstein Distance Minimization

Scenario weights for the following stresses are provided:

stress_wass calls one of the functions below by using type
stress_RM_w for stressing the distortion risk measure (RM) (type = "RM")
stress_mean_sd_w for stressing mean and standard deviation (type = "mean sd")
stress_RM_mean_sd_w for stressing the RM, mean and standard deviation (type = "RM mean sd")
stress_HARA_RM_w for stressing the HARA utility and RM (type = "HARA RM")

A <code>SWIM</code> object

A SWIM object is generated by applying a stress function subject to a relative entropy minimisation. An object of class SWIM contains a list of:

  • x, a data.frame containing realisations of a random vector;

  • new_weights, a list, each component corresponds to a different stress and is either a vector of scenario weights or a function, that applied to the kth column of x, generates the vectors of scenario weights;

  • type: a list, each component corresponds to a different stress and specifies the type of the stress;

  • specs, a list, each component corresponds to a different stress and contains a list with the specifications of what has been stressed. Specifications depend on the type of stress:

    • type = "VaR": k, the column of x on which the stress is applied to; alpha, the level of the stressed VaR; q, the stressed VaR at level alpha.

    • type = "VaR ES": k, the column of x on which the stress is applied to; alpha, the level of the stressed VaR and ES; q, the stressed VaR at level alpha.

    • type = "mean": k, the columns of x on which the stress is applied to; new_means, the stressed means.

    • type = "mean sd": k, the columns of x on which the stress is applied to; new_means, the stressed means; new_sd, the stressed standard deviations. s, the stressed ES at level alpha.

    • type = "moment": f, the list of functions, that, applied to x, constitute the moment constraints; k, the columns of x on which each function in f operates on; m, the stressed moments of f(x).

    • type = "prob": k, the column of x on which the stress is applied to; lower, the left endpoints of the intervals; upper, the right endpoints of the intervals; prob, stressed probabilities corresponding to the intervals defined through lower and upper.

    • type = "user": k, the column of x on which the stress is applied to.

A <code>SWIMw</code> object

A SWIMw object is generated by applying a stress function subject to a Wasserstein minimisation. The Wasserstein minimisation approach assumes that all model components, (random variables) are continuously distributed. If only the stressed model component is continuously distributed, the SWIMw stress should be converted to a SWIM object, see convert_SWIMw_to_SWIM. An object of class SWIMw contains a list of:

  • x, a data.frame containing realisations of a random vector;

  • new_weights: a list, each component corresponds to a different stress and is either a vector of scenario weights or a function, that applied to the kth column of x, generates the vectors of scenario weights;

  • type: a list, each component corresponds to a different stress and specifies the type of the stress;

  • h: a list, each component corresponds to a different stress and specifies the bandwidth;

  • u: a list, each component corresponds to a different stress and is a vector containing the gridspace on [0, 1];

  • lam: a list, each component corresponds to a different stress and is vector containing the lambda's of the optimized model;

  • str_fY: a list, each component corresponds to a different stress and is a function defining the densities of the stressed component;

  • str_FY: a list, each component corresponds to a different stress and is a function defining the distribution of the stressed component;

  • str_FY_inv: a list, each component corresponds to a different stress and is a function defining the quantiles of the stressed component;

  • gamma: a list, each component corresponds to a different stress and is a function defining the risk measure;

  • specs: a list, each component corresponds to a different stress and contains a list with the specifications of what has been stressed. Specifications depend on the type of stress:

    • type = "RM": k, the column of x on which the stress is applied to; alpha, the level of the RM; q, the stressed RM at level alpha.

    • type = "mean sd": k, the columns of x on which the stress is applied to; new_mean, the stressed mean; new_sd, the stressed standard deviation.

    • type = "RM mean sd": k, the column of x on which the stress is applied to; alpha, the level of the stressed RM; q, the stressed RM at level alpha; new_mean, the stressed mean; new_sd, the stressed standard deviation.

    • type = "HARA RM": k, the column of x on which the stress is applied to; alpha, the level of the stressed RM; q, the stressed RM at level alpha; a a parameter of the HARA utility function; b, a parameter of the HARA utility function; eta a parameter of the HARA utility function; hu, the stressed HARA utility with parameters a, b, and eta.

Details

The SWIM (Scenario Weights for Importance Measurement) package provides weights on simulated scenarios from a stochastic model, such that stressed random variables fulfil given probabilistic constraints (e.g. specified values for risk measures), under the new scenario weights. Scenario weights are selected by constrained minimisation of the relative entropy or Wasserstein distance to the baseline model.

The SWIM package is based on the reverse sensitivity framework developed by (Pesenti et al. 2019) and Pesenti2021SSRNSWIM.

Consider the random vector X = (X1,...,Xn). Let P represent the probability measure under which all simulated scenarios have the same probability. First, take the approach of minimizing the relative entropy. Then, for a random variable Xi, the package solves: $$min D(P | Q)$$ subject to constraints on the distribution of Xi under Q, where D(P | Q) is the Kullback-Leibler divergence (relative entropy) between P and Q.

The approach of minimizing the Wasserstein distance of order 2 proceeds as follows: Let F be the distribution function of the random variable Xi under P, then the package solves $$argmin_{G} W_{2}(G, F)$$ subject to constraints on G, W_{2}(G, F) is the 2-Wasserstein distance between G and F. The solution to the above minimisation problem is the distribution of Xi under Q. The current implementation of the Wasserstein approach is based on Kernel density estimation with Gaussian kernels.

For both approaches, the scenario weights are then formed via the Radon-Nikodym derivative dQ / dP. The weighting generates a model for which the joint distribution of (X1,...,Xn) is stressed.

Different elements of X can be understood as inputs or outputs of a model. For example, consider a model Y = g(Z) with input vector Z = (Z1,...,Z(n-1)). One can then identify X1 = Y and X2 = Z1,...,Xn = Z(n-1). Subsequently, the user of the SWIM package can stress the model output or any of the inputs, measuring the resulting impact on the distributions of other variables.

References

Pesenti2019reverseSWIM

Pesenti2020SSRNSWIM

Csiszar1975SWIM

See Also

See get_data for extracting the data, x; get_weights for extracting the scenario weights, new_weights; get_weightsfun for extracting the functions generating the scenario weights; and get_specs for extracting the specifications of the stress on an object of class SWIM.