kiener4: Asymmetric Kiener Distribution K4

Description Usage Arguments Details References See Also Examples

Description

Density, distribution function, quantile function, random generation, value-at-risk, expected shortfall (+ signed left/right tail mean) and additional formulae for asymmetric Kiener distribution K4.

Usage

 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
dkiener4(x, m = 0, g = 1, k = 3.2, e = 0, log = FALSE)

pkiener4(q, m = 0, g = 1, k = 3.2, e = 0, lower.tail = TRUE, log.p = FALSE)

qkiener4(p, m = 0, g = 1, k = 3.2, e = 0, lower.tail = TRUE, log.p = FALSE)

rkiener4(n, m = 0, g = 1, k = 3.2, e = 0)

dpkiener4(p, m = 0, g = 1, k = 3.2, e = 0, log = FALSE)

dqkiener4(p, m = 0, g = 1, k = 3.2, e = 0, log = FALSE)

lkiener4(x, m = 0, g = 1, k = 3.2, e = 0)

dlkiener4(lp, m = 0, g = 1, k = 3.2, e = 0, log = FALSE)

qlkiener4(lp, m = 0, g = 1, k = 3.2, e = 0, lower.tail = TRUE)

varkiener4(p, m = 0, g = 1, k = 3.2, e = 0, lower.tail = TRUE, log.p = FALSE)

ltmkiener4(p, m = 0, g = 1, k = 3.2, e = 0, lower.tail = TRUE, log.p = FALSE)

rtmkiener4(p, m = 0, g = 1, k = 3.2, e = 0, lower.tail = TRUE, log.p = FALSE)

dtmqkiener4(p, m = 0, g = 1, k = 3.2, e = 0, lower.tail = TRUE, log.p = FALSE)

eskiener4(p, m = 0, g = 1, k = 3.2, e = 0, lower.tail = TRUE,
  log.p = FALSE, signedES = FALSE)

Arguments

x

vector of quantiles.

m

numeric. The median.

g

numeric. The scale parameter, preferably strictly positive.

k

numeric. The tail parameter, preferably strictly positive.

e

numeric. The eccentricity parameter between left and right tails.

log

logical. If TRUE, densities are given in log scale.

q

vector of quantiles.

lower.tail

logical. If TRUE, use p. If FALSE, use 1-p.

log.p

logical. If TRUE, probabilities p are given as log(p).

p

vector of probabilities.

n

number of observations. If length(n) > 1, the length is taken to be the number required.

lp

vector of logit of probabilities.

signedES

logical. FALSE (default) returns positive numbers for left and right tails. TRUE returns negative number (= ltmkiener4) for left tail and positive number (= rtmkiener4) for right tail.

Details

Kiener distributions use the following parameters, some of them being redundant. See aw2k and pk2pk for the formulas and the conversion between parameters:

Kiener distributions K4(m, g, k, e, ...) are distributions with asymmetrical left and right fat tails described by a global tail parameter k and an eccentricity parameter e.

Distributions K3 (kiener3) with parameters k (kappa) and d (delta) and distributions K4 (kiener4) with parameters k (kappa) and e (epsilon)) have been created to disantangle the parameters a (alpha) and w (omega) of distributions K2 (kiener2). The tiny difference between distributions K3 and K4 (d = e/k) has not yet been fully evaluated. Both should be tested at that moment.

k is the harmonic mean of a and w and represents a global tail parameter.

e is an eccentricity parameter between the left tail parameter a and the right tail parameter w. It verifies the inequality: -1 < e < 1 (whereas d of distribution K3 verifies -k < d < k). The conversion functions (see aw2k) are:

1/k = (1/a + 1/w)/2

e = (a - w)/(a + w)

a = k/(1 - e)

w = k/(1 + e)

e (and d) should be of the same sign than the skewness. A negative value e < 0 implies a < w and indicates a left tail heavier than the right tail. A positive value e > 0 implies a > w and a right tail heavier than the left tail.

m is the median of the distribution. g is the scale parameter and the inverse of the density at the median: g = 1 / 8 / f(m) . As a first estimate, it is approximatively one fourth of the standard deviation g \approx σ / 4 but is independant from it.

The d, p functions have no explicit forms. They are provided here for convenience. They are estimated from a reverse optimization on the quantile function and can be (very) slow, depending the number of points to estimate. We recommand to use the quantile function as far as possible. WARNING: Results may become inconsistent when k is smaller than 1 or for very large absolute values of e. Hopefully, these cases seldom happen in finance.

qkiener4 function is defined for p in (0, 1) by:

qkiener4(p, m, g, k, e) = m + 2 * g * k * sinh(logit(p) / k) * exp(e / k * logit(p))

rkiener4 generates n random quantiles.

In addition to the classical d, p, q, r functions, the prefixes dp, dq, l, dl, ql are also provided.

dpkiener4 is the density function calculated from the probability p. The formula is adapted from distribution K2. It is defined for p in (0, 1) by:

dpkiener4(p, m, g, k, e) = p * (1 - p) / k / g / ( exp(-logit(p)/a)/a + exp(logit(p)/w)/w

with a and w defined from k and e.

dqkiener4 is the derivate of the quantile function calculated from the probability p. The formula is adapted from distribution K2. It is defined for p in (0, 1) by:

dqkiener4(p, m, g, k, e) = k * g / p / (1 - p) * ( exp(-logit(p)/a)/a + exp(logit(p)/w)/w )

with a and w defined with the formula presented above.

lkiener4 function is estimated from a reverse optimization and can be (very) slow depending the number of points to estimate. Initialization is done with a symmetric distribution lkiener1 of parameter k (thus e = 0). Then optimization is performed to take into account the true value of e. The results can then be compared to the empirical probability logit(p). WARNING: Results may become inconsistent when k is smaller than 1 or for very large absolute values of e. Hopefully, these cases seldom happen in finance.

dlkiener4 is the density function calculated from the logit of the probability lp = logit(p). The formula is adapted from distribution K2. it is defined for lp in (-Inf, +Inf) by:

dlkiener4(lp, m, g, k, e) = p * (1 - p) / k / g / ( exp(-lp/a)/a + exp(lp/w)/w )

with a and w defined above.

qlkiener4 is the quantile function calculated from the logit of the probability. It is defined for lp in (-Inf, +Inf) by:

qlkiener4(lp, m, g, k, e) = m + 2 * g * k * sinh(lp / k) * exp(e / k * lp)

varkiener4 designates the Value a-risk and turns negative numbers into positive numbers with the following rule:

varkiener4 <- if(p <= 0.5) { - qkiener4 } else { qkiener4 }

Usual values in finance are p = 0.01, p = 0.05, p = 0.95 and p = 0.99. lower.tail = FALSE uses 1-p rather than p.

ltmkiener4, rtmkiener4 and eskiener4 are respectively the left tail mean, the right tail mean and the expected shortfall of the distribution (sometimes called average VaR, conditional VaR or tail VaR). Left tail mean is the integrale from -Inf to p of the quantile function qkiener4 divided by p. Right tail mean is the integrale from p to +Inf of the quantile function qkiener4 divided by 1-p. Expected shortfall turns negative numbers into positive numbers with the following rule:

eskiener4 <- if(p <= 0.5) { - ltmkiener4 } else { rtmkiener4 }

Usual values in finance are p = 0.01, p = 0.025, p = 0.975 and p = 0.99. lower.tail = FALSE uses 1-p rather than p.

dtmqkiener4 is the difference between the left tail mean and the quantile when (p <= 0.5) and the difference between the right tail mean and the quantile when (p > 0.5). It is in quantile unit and is an indirect measure of the tail curvature.

References

P. Kiener, Explicit models for bilateral fat-tailed distributions and applications in finance with the package FatTailsR, 8th R/Rmetrics Workshop and Summer School, Paris, 27 June 2014. Download it from: https://www.inmodelia.com/exemples/2014-0627-Rmetrics-Kiener-en.pdf

P. Kiener, Fat tail analysis and package FatTailsR, 9th R/Rmetrics Workshop and Summer School, Zurich, 27 June 2015. Download it from: https://www.inmodelia.com/exemples/2015-0627-Rmetrics-Kiener-en.pdf

C. Acerbi, D. Tasche, Expected shortfall: a natural coherent alternative to Value at Risk, 9 May 2001. Download it from: https://www.bis.org/bcbs/ca/acertasc.pdf

See Also

Symmetric Kiener distribution K1 kiener1, asymmetric Kiener distributions K2, K3 and K7 kiener2, kiener3, kiener7, conversion functions aw2k, estimation function fitkienerX,

Examples

  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
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
require(graphics)

### Example 1
pp <- c(ppoints(11, a = 1), NA, NaN) ; pp
lp <- logit(pp) ; lp
qkiener4(  p = pp, m = 2, g = 1.5, k = aw2k(4, 6), e = aw2e(4, 6))
qlkiener4(lp = lp, m = 2, g = 1.5, k = aw2k(4, 6), e = aw2e(4, 6))
dpkiener4( p = pp, m = 2, g = 1.5, k = aw2k(4, 6), e = aw2e(4, 6))
dlkiener4(lp = lp, m = 2, g = 1.5, k = aw2k(4, 6), e = aw2e(4, 6))
dqkiener4( p = pp, m = 2, g = 1.5, k = aw2k(4, 6), e = aw2e(4, 6))


### Example 2
k       <- 4.8
e       <- 0.2
set.seed(2014)
mainTC  <- paste("qkiener4(p, m = 0, g = 1, k = ", k, ", e = ", e, ")")
mainsum <- paste("cumulated qkiener4(p, m = 0, g = 1, k = ", k, ", e = ", e, ")")
T       <- 500
C       <- 4
TC      <- qkiener4(p = runif(T*C), m = 0, g = 1, k = k, e = e)
matTC   <- matrix(TC, nrow = T, ncol = C, dimnames = list(1:T, letters[1:C]))
head(matTC)
plot.ts(matTC, main = mainTC)
#
matsum  <- apply(matTC, MARGIN=2, cumsum) 
head(matsum)
plot.ts(matsum, plot.type = "single", main = mainsum)
### End example 2


### Example 3 (four plots: probability, density, logit, logdensity)
x     <- q  <- seq(-15, 15, length.out=101)
k     <- 3.2
e     <- c(-0.3, -0.15, -0.07, 0.07, 0.15, 0.30) ; names(e) <- e
olty  <- c(2, 1, 2, 1, 2, 1, 1)
olwd  <- c(1, 1, 2, 2, 3, 3, 2)
ocol  <- c(2, 2, 4, 4, 3, 3, 1)
lleg  <- c("logit(0.999) = 6.9", "logit(0.99)   = 4.6", "logit(0.95)   = 2.9", 
           "logit(0.50)   = 0", "logit(0.05)   = -2.9", "logit(0.01)   = -4.6", 
           "logit(0.001) = -6.9  ")
op    <- par(mfrow=c(2,2), mgp=c(1.5,0.8,0), mar=c(3,3,2,1))

plot(x, pkiener4(x, k = 3.2, e = 0), type = "l", lwd = 3, ylim = c(0, 1),
     xaxs = "i", yaxs = "i", xlab = "", ylab = "", 
     main = "pkiener4(q, m, g, k=3.2, e=...)")
for (i in 1:length(e)) lines(x, pkiener4(x, k = 3.2, e = e[i]), 
       lty = olty[i], lwd = olwd[i], col = ocol[i] )
legend("topleft", title = expression(epsilon), legend = c(e, "0"), 
       cex = 0.7, inset = 0.02, lty = olty, lwd = olwd, col = ocol )

plot(x, dkiener4(x, k = 3.2, e = 0), type = "l", lwd = 3, ylim = c(0, 0.14),
     xaxs = "i", yaxs = "i", xlab = "", ylab = "", 
     main = "dkiener4(q, m, g, k=3.2, e=...)")
for (i in 1:length(e)) lines(x, dkiener4(x, k = 3.2, e = e[i]), 
       lty = olty[i], lwd = olwd[i], col = ocol[i] )
legend("topright", title = expression(epsilon), legend = c(e, "0"), 
       cex = 0.7, inset = 0.02, lty = olty, lwd = olwd, col = ocol )

plot(x, lkiener4(x, k = 3.2, e = 0), type = "l", lwd =3, ylim = c(-7.5, 7.5), 
     yaxt="n", xaxs = "i", yaxs = "i", xlab = "", ylab = "", 
     main = "logit(pkiener4(q, m, g, k=3.2, e=...))")
axis(2, las=1, at=c(-6.9, -4.6, -2.9, 0, 2.9, 4.6, 6.9) )
for (i in 1:length(e)) lines(x, lkiener4(x, k = 3.2, e = e[i]),  
       lty = olty[i], lwd = olwd[i], col = ocol[i] )
legend("topleft", legend = lleg, cex = 0.7, inset = 0.02 )
legend("bottomright", title = expression(epsilon), legend = c(e, "0"), 
       cex = 0.7, inset = 0.02, lty = c(olty), lwd = c(olwd), col = c(ocol) )

plot(x, dkiener4(x, k = 3.2, e = 0, log = TRUE), type = "l", lwd = 3, 
     ylim = c(-8, -1.5), xaxs = "i", yaxs = "i", xlab = "", ylab = "", 
     main = "log(dkiener4(q, m, g, k=2, e=...))")
for (i in 1:length(e)) lines(x, dkiener4(x, k = 3.2, e = e[i], log=TRUE), 
       lty = olty[i], lwd = olwd[i], col = ocol[i] )
legend("bottom", title = expression(epsilon), legend = c(e, "0"), 
       cex = 0.7, inset = 0.02, lty = olty, lwd = olwd, col = ocol )
### End example 3


### Example 4 (four plots: quantile, derivate, density and quantiles from p)
p     <- ppoints(199, a=0)
e     <- c(-0.3, -0.15, -0.07, 0.07, 0.15, 0.30) ; names(e) <- e
op    <- par(mfrow=c(2,2), mgp=c(1.5,0.8,0), mar=c(3,3,2,1))

plot(p, qlogis(p, scale = 2), type = "l", lwd = 2, xlim = c(0, 1),
     ylim = c(-15, 15), xaxs = "i", yaxs = "i", xlab = "", ylab = "", 
     main = "qkiener4(p, m, g, k=3.2, e=...)")
for (i in 1:length(e)) lines(p, qkiener4(p, k = 3.2, e = e[i]), 
          lty = olty[i], lwd = olwd[i], col = ocol[i] )
legend("topleft", title = expression(epsilon), legend = c(e, "qlogis(x/2)"), 
        inset = 0.02, lty = olty, lwd = olwd, col = ocol, cex = 0.7 )

plot(p, 2/p/(1-p), type = "l", lwd = 2, xlim = c(0, 1), ylim = c(0, 100),
     xaxs = "i", yaxs = "i", xlab = "", ylab = "", 
     main = "dqkiener4(p, m, g, k=3.2, e=...)")
for (i in 1:length(e)) lines(p, dqkiener4(p, k = 3.2, e = e[i]), 
          lty = olty[i], lwd = olwd[i], col = ocol[i] )
legend("top", title = expression(epsilon), legend = c(e, "p*(1-p)/2"), 
          inset = 0.02, lty = olty, lwd = olwd, col = ocol, cex = 0.7 )

plot(qlogis(p, scale = 2), p*(1-p)/2, type = "l", lwd = 2, xlim = c(-15, 15), 
     ylim = c(0, 0.14), xaxs = "i", yaxs = "i", xlab = "", ylab = "", 
     main = "qkiener4, dpkiener4(p, m, g, k=3.2, e=...)")
for (i in 1:length(e)) { 
     lines(qkiener4(p, k = 3.2, e = e[i]), dpkiener4(p, k = 3.2, e = e[i]),
           lty = olty[i], lwd = olwd[i], col = ocol[i] ) }
legend("topleft", title = expression(epsilon), legend = c(e, "p*(1-p)/2"), 
          inset = 0.02, lty = olty, lwd = olwd, col = ocol, cex = 0.7 )

plot(qlogis(p, scale = 2), p, type = "l", lwd = 2, xlim = c(-15, 15), 
     ylim = c(0, 1), xaxs = "i", yaxs = "i", xlab = "", ylab = "", 
     main = "inverse axis qkiener4(p, m, g, k=3.2, e=...)")
for (i in 1:length(e)) lines(qkiener4(p, k = 3.2, e = e[i]), p,
          lty = olty[i], lwd = olwd[i], col = ocol[i] )
legend("topleft", title = expression(epsilon), legend = c(e, "qlogis(x/2)"), 
          inset = 0.02, lty = olty, lwd = olwd, col = ocol, cex = 0.7 )
### End example 4


pp <- c(0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 
        0.10, 0.20, 0.35, 0.5, 0.65, 0.80, 0.90,
        0.95, 0.975, 0.99, 0.995, 0.9975, 0.999)
m <- -5 ; g <- 1 ; k <- 4 ; e = -0.20
a <- ek2a(e, k) ; w <- ek2w(e, k) ; d <- ek2d(e, k) 
round(c(m = m, g = g, a = a, k = k, w = w, d = d, e = e), 2) 
plot(qkiener4(pp, m, g, k, e), pp, type = "b")
round(cbind(p = pp, "1-p" = 1-pp,
	q   =   qkiener4(pp, m, g, k, e),
	ltm = ltmkiener4(pp, m, g, k, e),
	rtm = rtmkiener4(pp, m, g, k, e),
	ES  =  eskiener4(pp, m, g, k, e),
	VaR = varkiener4(pp, m, g, k, e)), 4)
round(kmean(c(m, g, k, e), model = "K4"), 4) # limit value for ltm and rtm
round(cbind(p = pp, "1-p" = 1-pp, 
	q   =   qkiener4(pp, m, g, k, e, lower.tail = FALSE), 
	ltm = ltmkiener4(pp, m, g, k, e, lower.tail = FALSE), 
	rtm = rtmkiener4(pp, m, g, k, e, lower.tail = FALSE), 
	ES  =  eskiener4(pp, m, g, k, e, lower.tail = FALSE), 
	VaR = varkiener4(pp, m, g, k, e, lower.tail = FALSE)), 4)
### End example 5

FatTailsR documentation built on March 12, 2021, 9:06 a.m.

Related to kiener4 in FatTailsR...