Description Usage Arguments Details Value Author(s) References See Also Examples
Provides different sensitivity measures that compare the stressed and the baseline model.
1 2 3 4 5 6 7 8 9 10 |
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 ( |
Provides sensitivity measures that compare the stressed and the baseline model. Implemented sensitivity measures:
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
\insertCitePesenti2019reverseSWIM. Loosely speaking, the
Reverse Sensitivity Measure is the normalised difference
between the first moment of the stressed and the baseline
distributions of Y
.
Kolmogorov
, the Kolmogorov distance, defined for
distribution functions F,G
by
Kolmogorov = sup |F(x) - G(x)|.
Wasserstein
, the Wasserstein distance of order 1, defined
for two distribution functions F,G
by
Wasserstein = \int |F(x) - G(x)| dx.
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.
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.
Silvana M. Pesenti, Zhuomin Mao
Pesenti2019reverseSWIM
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | ## 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.