FatTailsR-package | R Documentation |
This package includes Kiener distributions K1, K2, K3, K4 and K7 and two estimation algorithms to characterize with a high precision symmetric or asymmetric distributions with left and right fat tails that appear in market finance, neuroscience and many other disciplines. The estimation of the distribution parameters, quantiles, value-at-risk and expected shortfall is usually very accurate. Two datasets are provided, as well as power hyperbolas and power hyperbolic functions which are simplified versions of symmetric distribution K1.
Download the pdf cited in the references to get an overview of the theoretical part and several examples on stocks and indices.
A commercial package, FatTailsRplot
, with advanced plotting functions
and calculation of matrix of stocks over rolling windows is also developped
by the author.
With so many functions, this package could look fat. But it's not! It's rather agile and easy to use! The various functions included in this package can be assigned to the following groups:
Two datasets presented in different formats: list, data.frame, matrix, timeSeries, xts, zoo:
getDSdata
.
extractData
, dfData, mData, tData, xData, zData.
Functions to check the dimensions of vector, matrix, array, list:
dimdim
, dimdim1, dimdimc.
Functions to calculate (positive, negative) prices to returns on vector, matrix, array, list, data.frame, timeSeries, xts, zoo:
elevate
.
fatreturns
, logreturns.
Several predefined vectors of probability. One function to check them. A conversion function from probabilities to characters
pprobs0
, pprobs1, pprobs2, ..., pprobs9.
checkquantiles
.
getnamesk
.
Miscellaneous functions related to the logistic function:
logit
, invlogit, ltmlogis, rtmlogis, eslogis.
Power hyperbolas, power hyperbolic functions and their reciprocal functions:
exphp
, coshp, sinhp, tanhp, sechp, cosechp,
cotanhp.
loghp
, acoshp, asinhp, atanhp, asechp,
acosechp, acotanhp.
kashp
, dkashp_dx, ashp.
Logishp function, kogit and invkogit = logistic function + power hyperbolas:
d, p, q, r, dp, dq, l, dl, ql logishp
.
kogit
, invkogit.
Conversion functions between parameters related to Kiener distributions K1, K2, K3, K4:
aw2k
, aw2d, aw2e, ad2e, ad2k, ad2w, ae2d, ae2k,
ae2w, ak2e, ak2w, de2a, de2k, de2w, dk2a, dk2e, dw2a, dw2e,
dw2k, ek2a, ak2d, ek2w, aw2a, aw2d, ew2a, aw2d, ew2k, kd2a,
kd2e, kd2w, ke2a, ke2d, ke2w, kw2a, kw2d, kw2e.
pk2pk
.
Kiener distributions K1, K2, K3, K4 and the new K7 (introduced in v1.7-0):
d, p, q, r, dp, dq, l, dl, ql, var, ltm, rtm, dtmq, es kiener1
,
d, p, q, r, dp, dq, l, dl, ql, var, ltm, rtm, dtmq, es kiener2
,
d, p, q, r, dp, dq, l, dl, ql, var, ltm, rtm, dtmq, es kiener3
,
d, p, q, r, dp, dq, l, dl, ql, var, ltm, rtm, dtmq, es kiener4
,
d, p, q, r, dp, dq, l, dl, ql, var, ltm, rtm, dtmq, es kiener7
.
Quantile (VaR) corrective function (as a multiplier of the logistic function). Expected shortfall corrective function (as a multiplier of the expected shortfall of the logistic distribution):
ckiener1
, ckiener2, ckiener3, ckiener4, ckiener7.
hkiener1
, hkiener2, hkiener3, hkiener4, hkiener7.
Moments of the distribution estimated from the dataset and from the regression parameters:
xmoments
.
kmoments
, kmoment, kcmoment, kmean,
kstandev, kvariance, kskewness, kkurtosis, kekurtosis.
Regression and estimation functions to estimate Kiener distribution
parameters on a given dataset. *fit*
and *param*
are wrappers of algorithms reg
and estim
.
reg
uses an unweighted nonlinear regression function.
estim
uses a fast estimation based on quantiles:
regkienerLX
, laplacegaussnorm
.
fitkienerX
.
paramkienerX, paramkienerX5, paramkienerX7
.
Functions related to paramkienerX
:
elevenprobs
, sevenprobs, fiveprobs.
estimkiener11
, estimkiener7, estimkiener5.
roundcoefk
.
checkcoefk
.
Predefined subsets of parameters to extract them
from the long vector fitk
obtained after regression/estimation
regkienerLX
, fitkienerX
:
exfit0
, ..., exfit7
.
For a quick start, jump to the functions regkienerLX
,
fitkienerX
and run the examples.
Then, download and read the documents in pdf format cited in the references
to get an overview on the major functions. Finally, explore the other
examples.
Maintainer: Patrice Kiener fattailsr@inmodelia.com (ORCID)
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
Useful links:
require(graphics)
require(minpack.lm)
require(timeSeries)
### Load the datasets and select one number (1-16)
DS <- getDSdata()
j <- 5
### and run this block
X <- DS[[j]]
nameX <- names(DS)[j]
reg <- regkienerLX(X)
lgn <- laplacegaussnorm(X)
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 ")
pleg <- c( paste("m =", reg$coefr4[1]), paste("g =", reg$coefr4[2]),
paste("k =", reg$coefr4[3]), paste("e =", reg$coefr4[4]) )
## Main plot
op <- par(mfrow = c(1,1), mgp = c(1.5,0.8,0), mar = c(3,3,2,1))
plot(reg$dfrXP, main = nameX)
legend("top", legend = pleg, cex = 0.9, inset = 0.02 )
lines(reg$dfrEP, col = 2, lwd = 2)
points(reg$dfrQkPk, pch = 3, col = 2, lwd = 2, cex = 1.5)
lines(lgn$dfrXPn, col = 7, lwd = 2)
## Plot F(X) > 0,97
front = c(0.06, 0.39, 0.50, 0.95)
par(fig = front, new = TRUE, mgp = c(1.5, 0.6, 0), las = 0)
plot( reg$dfrXP[which(reg$dfrXP$P > 0.97),] , pch = 1, xlab = "", ylab = "", main = "F(X) > 0,97" )
lines(reg$dfrEP[which(reg$dfrEP$P > 0.97),], type="l", col = 2, lwd = 3 )
lines(lgn$dfrXPn[which(lgn$dfrXPn$Pn > 0.97),], type = "l", col = 7, lwd= 2 )
points(reg$dfrQkPk, pch = 3, col = 2, lwd = 2, cex = 1.5)
points(lgn$dfrQnPn, pch = 3, col = 7, lwd = 2, cex = 1)
## Plot F(X) < 0,03
front = c(0.58, 0.98, 0.06, 0.61)
par(fig = front, new = TRUE, mgp = c(0.5, 0.6, 0), las = 0 )
plot( reg$dfrXP[which(reg$dfrXP$P < 0.03),] , pch = 1, xlab = "", ylab = "", main = "F(X) < 0,03")
lines(reg$dfrEP[which(reg$dfrEP$P < 0.03),], type = "l", col = 2, lwd = 3 )
lines(lgn$dfrXPn[which(lgn$dfrXPn$Pn < 0.03),], type = "l", col= 7, lwd= 2 )
points(reg$dfrQkPk, pch = 3, col = 2, lwd = 2, cex = 1.5)
points(lgn$dfrQnPn, pch = 3, col = 7, lwd = 2, cex = 1)
## Moments from the parameters (k) and from the Dataset (X)
round(cbind("k" = kmoments(reg$coefk, lengthx = nrow(reg$dfrXL)), "X" = xmoments(X)), 2)
attributes(reg)
### End block
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.