sensitivity {SWIM}R Documentation

Sensitivities of a Stressed Model

Description

Provides different sensitivity measures that compare the stressed and the baseline model.

Usage

sensitivity(
  object,
  xCol = "all",
  wCol = "all",
  type = c("Gamma", "Kolmogorov", "Wasserstein", "reverse", "all"),
  f = NULL,
  k = NULL,
  s = NULL,
  p = 1
)

Arguments

object

A SWIM or SWIMw object.

xCol

Numeric or character vector, (names of) the columns of the underlying data of the object (default = "all"). If xCol = NULL, only the transformed data f(x) is considered.

wCol

Vector, the columns of the scenario weights of the object corresponding to different stresses (default = "all").

type

Character, one of "Gamma", "Kolmogorov", "Wasserstein", "reverse", "all" (default = "all").

f

A function, or list of functions, that, applied to x, constitute the transformation of the data for which the sensitivity is calculated.

k

A vector or list of vectors, same length as f, indicating which columns of x each function in f operates on.
When f is a list, k[[i]] corresponds to the input variables of f[[i]].

s

A function that, applied to x, defines the reverse sensitivity measure. If type = "reverse" and s = NULL, defaults to type = "Gamma".

p

Numeric vector, the p-th moment of Wasserstein distance (default = 1).

Details

Provides sensitivity measures that compare the stressed and the baseline model. Implemented sensitivity measures:

  1. Gamma, the Reverse Sensitivity Measure, defined for a random variable Y and scenario weights w by

    Gamma = ( E(Y * w) - E(Y) ) / c,

    where c is a normalisation constant such that |Gamma| <= 1, see (Pesenti et al. 2019). Loosely speaking, the Reverse Sensitivity Measure is the normalised difference between the first moment of the stressed and the baseline distributions of Y.

  2. Kolmogorov, the Kolmogorov distance, defined for distribution functions F,G by

    Kolmogorov = sup |F(x) - G(x)|.

  3. Wasserstein, the Wasserstein distance of order 1, defined for two distribution functions F,G by

    Wasserstein = \int |F(x) - G(x)| dx.

  4. reverse, the General Reverse Sensitivity Measure, defined for a random variable Y, scenario weights w, and a function s:R -> R by

    epsilon = ( E(s(Y) * w) - E(s(Y)) ) / c,

    where c is a normalisation constant such that |epsilon| <= 1. Gamma is a special instance of the reverse sensitivity measure when s is the identity function.

If f and k are provided, the sensitivity of the transformed data is returned.

Value

A data.frame containing the sensitivity measures of the stressed model with rows corresponding to different random variables. The first two rows specify the stress and type of the sensitivity measure.

Author(s)

Silvana M. Pesenti, Zhuomin Mao

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.

See Also

See importance_rank for ranking of random variables according to their sensitivities, plot_sensitivity for plotting sensitivity measures and summary for summary statistics of a stressed model.

Examples

## example with a stress on VaR
set.seed(0)
x <- as.data.frame(cbind(
  "log-normal" = rlnorm(1000),
  "gamma" = rgamma(1000, shape = 2)))
res1 <- stress(type = "VaR", x = x,
  alpha = c(0.9, 0.95), q_ratio = 1.05)

sensitivity(res1, wCol = 1, type = "all")
## sensitivity of log-transformed data
sensitivity(res1, wCol = 1, type = "all",
  f = list(function(x)log(x), function(x)log(x)), k = list(1,2))

## Consider the portfolio Y = X1 + X2 + X3 + X4 + X5,
## where (X1, X2, X3, X4, X5) are correlated normally
## distributed with equal mean and different standard deviations,
## see the README for further details.


## Not run: 
set.seed(0)
SD <- c(70, 45, 50, 60, 75)
Corr <- matrix(rep(0.5, 5 ^ 2), nrow = 5) + diag(rep(1 - 0.5, 5))
if (!requireNamespace("mvtnorm", quietly = TRUE))
   stop("Package \"mvtnorm\" needed for this function
   to work. Please install it.")
x <- mvtnorm::rmvnorm(10 ^ 5,
   mean =  rep(100, 5),
   sigma = (SD %*% t(SD)) * Corr)
data <- data.frame(rowSums(x), x)
names(data) <- c("Y", "X1", "X2", "X3", "X4", "X5")
rev.stress <- stress(type = "VaR", x = data,
   alpha = c(0.75, 0.9), q_ratio = 1.1, k = 1)

sensitivity(rev.stress, type = "all")
## sensitivity to sub-portfolios X1 + X2 and X3 + X4
sensitivity(rev.stress, xCol = NULL, type = "Gamma",
  f = rep(list(function(x)x[1] + x[2]), 2), k = list(c(2, 3), c(4, 5)))
plot_sensitivity(rev.stress, xCol = 2:6, type = "Gamma")
importance_rank(rev.stress, xCol = 2:6, type = "Gamma")

## End(Not run)


[Package SWIM version 1.0.0 Index]