ghyp-distribution: The Generalized Hyperbolic Distribution

Description Usage Arguments Details Value Note Author(s) References See Also Examples

Description

Density, distribution function, quantile function, expected-shortfall and random generation for the univariate and multivariate generalized hyperbolic distribution and its special cases.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
dghyp(x, object = ghyp(), logvalue = FALSE)

pghyp(q, object = ghyp(), n.sim = 10000, subdivisions = 200,
      rel.tol = .Machine$double.eps^0.5, abs.tol = rel.tol,
      lower.tail = TRUE)

qghyp(p, object = ghyp(), method = c("integration", "splines"),
      spline.points = 200, subdivisions = 200,
      root.tol = .Machine$double.eps^0.5,
      rel.tol = root.tol^1.5, abs.tol = rel.tol)

rghyp(n, object = ghyp())

Arguments

p

A vector of probabilities.

x

A vector, matrix or data.frame of quantiles.

q

A vector, matrix or data.frame of quantiles.

n

Number of observations.

object

An object inheriting from class ghyp.

logvalue

If TRUE the logarithm of the density will be returned.

n.sim

The number of simulations when computing pghyp of a multivariate generalized hyperbolic distribution.

subdivisions

The number of subdivisions passed to integrate when computing the distribution function pghyp of a univariate generalized hyperbolic distribution.

rel.tol

The relative accuracy requested from integrate.

abs.tol

The absolute accuracy requested from integrate.

lower.tail

If TRUE (default), probabilities are P[X <= x], otherwise, P[X > x].

method

The method how quantiles are computed (see Details).

spline.points

The number of support points when computing the quantiles with the method “splines” instead of “integration”.

root.tol

The tolerance of uniroot.

Details

qghyp only works for univariate generalized hyperbolic distributions.

pghyp performs a numeric integration of the density in the univariate case. The multivariate cumulative distribution is computed by means of monte carlo simulation.

qghyp computes the quantiles either by using the “integration” method where the root of the distribution function is solved or via “splines” which interpolates the distribution function and solves it with uniroot afterwards. The “integration” method is recommended when only few quantiles are required. If more than approximately 20 quantiles are needed to be calculated the “splines” method becomes faster. The accuracy can be controlled with an adequate setting of the parameters rel.tol, abs.tol, root.tol and spline.points.

rghyp uses the random generator for generalized inverse Gaussian distributed random variates from the Rmetrics package fBasics (cf. rgig).

Value

dghyp gives the density,
pghyp gives the distribution function,
qghyp gives the quantile function,
rghyp generates random deviates.

Note

Objects generated with hyp, NIG, VG and student.t have to use Xghyp as well. E.g. dNIG(0, NIG()) does not work but dghyp(0, NIG()).

When the skewness becomes very large the functions using qghyp may fail. The functions qqghyp, pairs and portfolio.optimize are based on qghyp.

Author(s)

David Luethi

References

ghyp-package vignette in the doc folder or on http://cran.r-project.org/web/packages/ghyp/ and references therein.

See Also

ghyp-class definition, ghyp constructors, fitting routines fit.ghypuv and fit.ghypmv, risk and performance measurement ESghyp and ghyp.omega, transformation and subsettting of ghyp objects, integrate, spline.

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
  ## Univariate generalized hyperbolic distribution
  univariate.ghyp <- ghyp()

  par(mfrow=c(5, 1))

  quantiles <- seq(-4, 4, length = 500)
  plot(quantiles, dghyp(quantiles, univariate.ghyp))
  plot(quantiles, pghyp(quantiles, univariate.ghyp))

  probabilities <- seq(1e-4, 1-1e-4, length = 500)
  plot(probabilities, qghyp(probabilities, univariate.ghyp, method = "splines"))

  hist(rghyp(n=10000,univariate.ghyp),nclass=100)

  ## Mutivariate generalized hyperbolic distribution
  multivariate.ghyp <- ghyp(sigma=var(matrix(rnorm(10),ncol=2)),mu=1:2,gamma=-(2:1))

  par(mfrow=c(2, 1))

  quantiles <- outer(seq(-4, 4, length = 50), c(1, 1))
  plot(quantiles[, 1], dghyp(quantiles, multivariate.ghyp))
  plot(quantiles[, 1], pghyp(quantiles, multivariate.ghyp, n.sim = 1000))

  rghyp(n = 10, multivariate.ghyp)

Example output

Loading required package: numDeriv
Loading required package: gplots

Attaching package: 'gplots'

The following object is masked from 'package:stats':

    lowess

Warning message:
In sqrt(W) * object@sigma :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

Warning messages:
1: In (psi + skewness.norm) * (chi + Q) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

2: In (psi + skewness.norm) * (chi + Q) :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

3: In log.const.top + log.top :
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

            [,1]       [,2]
 [1,] -0.7867745  1.1444433
 [2,] -0.4293804  1.5234580
 [3,] -1.2567174  0.9377993
 [4,] -5.5182777 -1.9699162
 [5,] -0.1517044  2.0284319
 [6,] -2.3160379  1.2776519
 [7,]  0.9906273  1.8608774
 [8,] -2.3952793  0.9876851
 [9,]  0.7711415  1.9107643
[10,] -1.3625128  1.1549386

ghyp documentation built on May 2, 2019, 6:09 p.m.