SWIM {SWIM} | R Documentation |
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.
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 (Pesenti 2021).
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.
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" ) |
stress_mean_w | for stressing mean (type = "mean" )
|
A SWIM
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 thek
th column ofx
, 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 thetype
of stress:-
type = "VaR"
:k
, the column ofx
on which the stress is applied to;alpha
, the level of the stressed VaR;q
, the stressed VaR at levelalpha
. -
type = "VaR ES"
:k
, the column ofx
on which the stress is applied to;alpha
, the level of the stressed VaR and ES;q
, the stressed VaR at levelalpha
. -
type = "mean"
:k
, the columns ofx
on which the stress is applied to;new_means
, the stressed means. -
type = "mean sd"
:k
, the columns ofx
on which the stress is applied to;new_means
, the stressed means;new_sd
, the stressed standard deviations.s
, the stressed ES at levelalpha
. -
type = "moment"
:f
, the list of functions, that, applied tox
, constitute the moment constraints;k
, the columns ofx
on which each function inf
operates on;m
, the stressed moments off(x)
. -
type = "prob"
:k
, the column ofx
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 throughlower
andupper
. -
type = "user"
:k
, the column ofx
on which the stress is applied to.
-
A SWIMw
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 thek
th column ofx
, 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 thetype
of stress:-
type = "RM"
:k
, the column ofx
on which the stress is applied to;alpha
, the level of the RM;q
, the stressed RM at levelalpha
. -
type = "mean sd"
:k
, the columns ofx
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 ofx
on which the stress is applied to;alpha
, the level of the stressed RM;q
, the stressed RM at levelalpha
;new_mean
, the stressed mean;new_sd
, the stressed standard deviation. -
type = "HARA RM"
:k
, the column ofx
on which the stress is applied to;alpha
, the level of the stressed RM;q
, the stressed RM at levelalpha
;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 parametersa
,b
, andeta
.
-
References
Pesenti SM, Millossovich P, Tsanakas A (2019).
“Reverse sensitivity testing: What does it take to break the model?”
European Journal of Operational Research, 274(2), 654–670.
Pesenti S BAMPTA (2020).
“Scenario Weights for Importance Measurement (SWIM) - An R package for sensitivity analysis.”
Annals of Actuarial Science 15.2 (2021): 458-483. Available at SSRN: https://www.ssrn.com/abstract=3515274.
Csiszar I (1975). “I-divergence geometry of probability distributions and minimization problems.” The Annals of Probability, 146–158.
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
.