FatTailsR-package {FatTailsR} | R Documentation |
Package FatTailsR
Description
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.
Details
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:
-
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:
-
fatreturns
, logreturns.
Several predefined vectors of probability. One function to check them. A conversion function from probabilities to characters
-
pprobs0
, pprobs1, pprobs2, ..., pprobs9.
-
Miscellaneous functions related to the logistic function:
-
logit
, invlogit, ltmlogis, rtmlogis, eslogis.
-
Power hyperbolas, power hyperbolic functions and their reciprocal functions:
Logishp function, kogit and invkogit = logistic function + power hyperbolas:
Conversion functions between parameters related to Kiener distributions K1, K2, K3, K4:
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):
Moments of the distribution estimated from the dataset and from the regression parameters:
Regression and estimation functions to estimate Kiener distribution parameters on a given dataset.
*fit*
and*param*
are wrappers of algorithmsreg
andestim
.reg
uses an unweighted nonlinear regression function.estim
uses a fast estimation based on quantiles:-
paramkienerX, paramkienerX5, paramkienerX7
.
Functions related to
paramkienerX
:-
elevenprobs
, sevenprobs, fiveprobs. -
estimkiener11
, estimkiener7, estimkiener5.
-
Predefined subsets of parameters to extract them from the long vector
fitk
obtained after regression/estimationregkienerLX
,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.
Author(s)
Maintainer: Patrice Kiener fattailsr@inmodelia.com (ORCID)
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
See Also
Useful links:
Examples
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