3 Scope of the SWIM package
3.1 Stressing a model
We briefly introduce key concepts, using slightly more technical language compared to Section 2. A model consists of a random vector of model components \(\mathbf X = (X_1,\dots,X_d)\) and a probability measure; we denote the probability measure of a baseline model by \(P\) and that of a stressed model by \(P^W\), where \(W= \frac{dP^W}{dP}\), satisfying \(E(W)=1\) and \(W\geq 0\), is a Radon-Nikodym derivative. In a Monte Carlo simulation context, the probability space is discrete with \(n\) states \(\Omega=\{\omega_1,\dots,\omega_n\}\), each of which corresponds to a simulated scenario. To reconcile this formulation with the notation of Section 2, we denote, for \(i=1, \dots, n,~j=1,\dots, d\), the realisations \(X_j(\omega_i):= x_{ji}\) and \(W(\omega_i):=w_i\); the latter are the scenario weights. Under the baseline model, each scenario has the same probability \(P(\omega_i)=1/n\), while under a stressed model it is \(P^W(\omega_i)=W(\omega_i)/n=w_i/n\).
The stressed model thus arises from a change of measure from \(P\) to \(P^W\), which entails the application of scenario weights \(w_1,\dots, w_n\) on individual simulations. SWIM calculates scenario weights such that model components fulfil specific stresses, while the distortion to the baseline model is as small as possible when measured by the Kullback-Leibler divergence (or relative entropy). Mathematically, a stressed model is derived by solving
\[\begin{equation} \min_{ W } ~E(W \log (W)), \quad \text{subject to constraints on } \mathbf X \text{ under } P^W. \tag{3.1} \end{equation}\] In what follows, we denote by a superscript \(W\) quantities of interest under the stressed model, such as \(F^W, ~ E^W\) for the probability distribution and expectation under the stressed model, respectively. We refer to Pesenti, Millossovich, and Tsanakas (2019) and references therein for further mathematical details and derivations of solutions to (3.1).
Table 3.1 provides a collection of all implemented types of stresses in the SWIM package. The precise constraints of (3.1) are explained below.
R function | Stress | type |
Reference |
---|---|---|---|
stress |
wrapper for the stress_type functions |
Sec. 3.1.1 | |
stress_user |
user defined scenario weights | user |
Sec. 3.1.5 |
stress_prob |
probabilities of disjoint intervals | prob |
Eq. (3.2) |
stress_mean |
means | mean |
Eq. (3.3) |
stress_mean_sd |
means and standard deviations | mean sd |
Eq. (3.4) |
stress_moment |
moments (of functions) | moment |
Eq. (3.5) |
stress_VaR |
VaR risk measure (quantile) | VaR |
Eq. (3.6) |
stress_VaR_ES |
VaR and ES risk measures | VaR ES |
Eq. (3.7) |
The solutions to the optimisations (3.2) and (3.6) are worked out fully analytically (Pesenti, Millossovich, and Tsanakas 2019), whereas problems (3.3), (3.4), (3.5) and (3.7) require some root-finding. Specifically, problems (3.3), (3.4) and (3.5) rely on the package nleqslv, whereas (3.7) uses the uniroot
function.
3.1.1 The stress
function and the SWIM object
The stress
function is a wrapper for the stress_type
functions, where stress(type = "type", )
and stress_type
are equivalent. The stress
function solves optimisation (3.1) for constraints specified through type
and returns a SWIM
object, that is, a list including the elements shown in Table 3.2:
x |
realisations of the model |
new_weights |
scenario weights |
type |
type of stress |
specs |
details about the stress |
The data frame containing the realisations of the baseline model, x
in the above table, can be extracted from a SWIM object using get_data
. Similarly, get_weights
and get_weightsfun
provide the scenario weights, respectively the functions that, when applied to x
, generate the scenario weights. The details of the applied stress can be obtained using get_specs
.
3.1.2 Stressing disjoint probability intervals
Stressing probabilities of disjoint intervals allows defining stresses by altering the probabilities of events pertaining to a model component. The scenario weights are calculated via stress_prob
, or equivalently stress(type = "prob", )
, and the disjoint intervals are specified through the lower
and upper
arguments, the endpoints of the intervals. Specifically,
stress_prob
solves (3.1) with the constraints \[\begin{equation} P^W(X_j \in B_k) = \alpha_k, ~k = 1, \ldots, K, \tag{3.2} \end{equation}\] for disjoint intervals \(B_1, \ldots, B_K\) with \(P(X_j \in B_k) >0\) for all \(k = 1, \ldots, K\), and \(\alpha_1, \ldots, \alpha_K > 0\) such that \(\alpha_1 + \ldots + \alpha_K \leq 1\) and a model component \(X_j\).
3.1.3 Stressing moments
The functions stress_mean
, stress_mean_sd
and stress_moment
provide stressed models with moment constraints. The function stress_mean
returns a stressed model that fulfils constraints on the first moment of model components. Specifically,
stress_mean
solves (3.1) with the constraints \[\begin{equation} E^W(X_j) = m_j, ~j \in J, \tag{3.3} \end{equation}\] for \(m_j, ~ j \in J\), where \(J\) is a subset of \(\{1, \ldots, d\}\).
The arguments \(m_j\) are specified in the stress_mean
function through the argument new_means
. The stress_mean_sd
function allows to stress simultaneously the mean and the standard deviation of model components. Specifically,
stress_mean_sd
solves (3.1) with the constraints \[\begin{equation} E^W(X_j) = m_j \text{ and Var}^W(X_j) = s_j^2 , ~j \in J, \tag{3.4} \end{equation}\] for \(m_j, s_j, ~ j \in J\), where \(J\) is a subset of \(\{1, \ldots, d\}\).
The arguments \(m_j, s_j\) are defined in the stress_mean_sd
function by the arguments new_means
and new_sd
respectively. The functions stress_mean
and stress_mean_sd
are special cases of the general stress_moment
function, which allows for stressed models with constraints on functions of the (joint) moments of model components. Specifically
For \(k = 1, \ldots, K\), \(J_k\) subsets of \(\{1, \ldots, d\}\) and functions \(f_k \colon \mathbb{R}^{|J_k|} \to \mathbb{R}\),
stress_moment
solves (3.1) with the constraints \[\begin{equation} E^W(f_k(\mathbf X_{J_k}) ) = m_k, ~k = 1, \ldots, K, \tag{3.5} \end{equation}\] for \(m_k, ~k=1, \dots,K\) and \(\mathbf X_{J_k}\) the subvector of model components with indices in \(J_k\).
Note that stress_moment
not only allows to define constraints on higher moments of model components, but also to construct constraints that apply to multiple model components simultaneously. For example, the stress \(E^W(X_h X_l) =m_k\) is achieved by setting \(f_k(x_h, x_l) = x_h x_l\) in (3.5) above. The functions stress_mean
, stress_mean_sd
and stress_moment
can be applied to multiple model components and are the only stress
functions that have scenario weights calculated via numerical optimisation, using the nleqslv package. Thus, depending on the choice of constraints, existence or uniqueness of a stressed model is not guaranteed.
3.1.4 Stressing risk measures
The functions stress_VaR
and stress_VaR_ES
provide stressed models, under which a model component fulfils a stress on the risk measures Value-at-Risk (\(\text{VaR}\)) and/or Expected Shortfall (\(\text{ES}\)). The \(\text{VaR}\) at level \(0 < \alpha < 1\) of a random variable \(Z\) with distribution \(F\) is defined as its left-inverse evaluated at \(\alpha\), that is
\[\text{VaR}_\alpha(Z) = F^{-1}(\alpha) = \inf\{ y \in \mathbb{R} ~|~F(y) \geq \alpha\}.\]
The \(\text{ES}\) at level \(0 < \alpha < 1\) of a random variable \(Z\) is given by \[\text{ES}_\alpha(Z) =\frac{1}{1-\alpha}\int_\alpha^1 \text{VaR}_u(Z) \mathrm{d}u.\]
The details of the constraints that stress_VaR
and stress_VaR_ES
solve, are as follows:
For \(0< \alpha <1\) and \(q, s\) such that \(q < s\),
stress_VaR
solves (3.1) with the constraint \[\begin{equation} \text{VaR}_{\alpha }^W(X_j) = q; \tag{3.6} \end{equation}\] andstress_VaR_ES
solves (3.1) with the constraints \[\begin{equation} \text{VaR}_{\alpha }^W(X_j) = q \text{ and ES}_{\alpha }^W(X_j) = s.\tag{3.7} \end{equation}\]
Note that, since SWIM works with discrete distributions, the exact required VaR may not be achievable. In that case, stress_VaR
will return scenario weights inducing the largest quantile in the dataset smaller or equal to the required VaR (i.e. \(q\)); this guarantees that \(P^W(X_j\leq q)=\alpha\).
3.1.5 User defined scenario weights
The option type = "user"
allows to generate a SWIM object with scenario weights defined by a user. The scenario weights can be provided directly via the new_weights
argument or through a list of functions, new_weightsfun
, that applied to the data x
generates the scenario weights.
3.2 Analysis of stressed models
Table 3.3 provides a complete list of all implemented R functions in SWIM for analysing stressed models, which are described below in detail.
R function | analysis of stressed models |
---|---|
summary |
summary statistics |
cdf |
cumulative distribution function |
quantile_stressed |
quantile function |
VaR_stressed |
VaR |
ES_stressed |
ES |
sensitivity |
sensitivity measures |
importance_rank |
importance ranks |
plot_cdf |
plots cumulative distributions functions |
plot_hist |
plots histograms |
plot_sensitivity |
plots sensitivity measures |
3.2.1 Distributional comparison
The SWIM package contains functions to compare the distribution of model components under different (stressed) models. The function summary
is a method for an object of class SWIM and provides summary statistics of the baseline and stressed models. If the SWIM object contains more than one set of scenario weights, each corresponding to one stressed model, the summary
function returns for each set of scenario weights a list, containing the elements shown in Table 3.4.
mean |
sample mean |
sd |
sample standard deviation |
skewness |
sample skewness |
ex kurtosis |
sample excess kurtosis |
1st Qu. |
\(25%\) quantile |
Median |
median, \(50%\) quantile |
3rd Qu. |
\(75%\) quantile |
The empirical distribution function of model components under a stressed model2 can be calculated using the cdf
function of the SWIM package, applied to a SWIM object. To calculate sample quantiles of stressed model components, the function quantile_stressed
can be used. The function VaR_stressed
and ES_stressed
provide the stressed VaR and ES of model components, which is of particular interest for stressed models resulting from constraints on risk measures, see Section 3.1.4. (While quantile_stressed
works very similarly to the base R function quantile
, VaR_stressed
provides better capabilities for comparing different models and model components.)
Implemented visualisation of distribution functions are plot_cdf
, for plotting empirical distribution functions, and plot_hist
, for plotting histograms of model components under different (stressed) models.
3.2.2 Sensitivity measures
Comparison of baseline and stressed models and how model components change under different models, is typically done via sensitivity measures. The SWIM packages contains the sensitivity
function, which calculates sensitivity measures of stressed models and model components. The implemented sensitivity measures, summarised in the table below, are the Wasserstein, Kolmogorov and the Gamma sensitivity measures, see Pesenti, Millossovich, and Tsanakas (2016) Pesenti, Millossovich, and Tsanakas (2019) Emmer, Kratz, and Tasche (2015).
Metric | Definition | |
---|---|---|
Wasserstein | \(\int | F^W_X (x) - F_X(x)| dx\) | |
Kolmogorov | \(\sup_x |F^W_X (x) - F_X(x)|\) | |
Gamma | \(\frac{E^W(X) - E(X)}{c}\), for a normalisation \(c\) |
The Gamma sensitivity measure is normalised such that it takes values between -1 and 1, with higher positive (negative) values corresponding to a larger positive (negative) impact of the stress on the particular model component. The sensitivity measures can be plotted using plot_sensitivity
. The function importance_rank
returns the effective rank of model components according to the chosen sensitivity measure.
Note that functions implementing the empirical cdf or the quantile,
ecdf
andquantile
, will not return the empirical distribution function or the quantile function under a stressed model.↩