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 |
xCol |
Numeric or character vector, (names of) the columns
of the underlying data of the |
wCol |
Vector, the columns of the scenario weights
of the |
type |
Character, one of |
f |
A function, or list of functions, that, applied to
|
k |
A vector or list of vectors, same length as |
s |
A function that, applied to |
p |
Numeric vector, the p-th moment of Wasserstein distance ( |
Details
Provides sensitivity measures that compare the stressed and the baseline model. Implemented sensitivity measures:
-
Gamma
, the Reverse Sensitivity Measure, defined for a random variableY
and scenario weightsw
byGamma = ( 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 ofY
. -
Kolmogorov
, the Kolmogorov distance, defined for distribution functionsF,G
byKolmogorov = sup |F(x) - G(x)|.
-
Wasserstein
, the Wasserstein distance of order 1, defined for two distribution functionsF,G
byWasserstein = \int |F(x) - G(x)| dx.
-
reverse
, the General Reverse Sensitivity Measure, defined for a random variableY
, scenario weightsw
, and a functions:R -> R
byepsilon = ( 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 whens
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)