\HeaderA{GarchDistributions}{GARCH Distributions and Parameter Estimation}{GarchDistributions}
\aliasA{absMoments}{GarchDistributions}{absMoments}
\aliasA{dged}{GarchDistributions}{dged}
\aliasA{dsged}{GarchDistributions}{dsged}
\aliasA{dsnorm}{GarchDistributions}{dsnorm}
\aliasA{dsstd}{GarchDistributions}{dsstd}
\aliasA{dstd}{GarchDistributions}{dstd}
\aliasA{gedFit}{GarchDistributions}{gedFit}
\aliasA{normFit}{GarchDistributions}{normFit}
\aliasA{pged}{GarchDistributions}{pged}
\aliasA{psged}{GarchDistributions}{psged}
\aliasA{psnorm}{GarchDistributions}{psnorm}
\aliasA{psstd}{GarchDistributions}{psstd}
\aliasA{pstd}{GarchDistributions}{pstd}
\aliasA{qged}{GarchDistributions}{qged}
\aliasA{qsged}{GarchDistributions}{qsged}
\aliasA{qsnorm}{GarchDistributions}{qsnorm}
\aliasA{qsstd}{GarchDistributions}{qsstd}
\aliasA{qstd}{GarchDistributions}{qstd}
\aliasA{rged}{GarchDistributions}{rged}
\aliasA{rsged}{GarchDistributions}{rsged}
\aliasA{rsnorm}{GarchDistributions}{rsnorm}
\aliasA{rsstd}{GarchDistributions}{rsstd}
\aliasA{rstd}{GarchDistributions}{rstd}
\aliasA{sgedFit}{GarchDistributions}{sgedFit}
\aliasA{snormFit}{GarchDistributions}{snormFit}
\aliasA{sstdFit}{GarchDistributions}{sstdFit}
\aliasA{stdFit}{GarchDistributions}{stdFit}
\keyword{distribution}{GarchDistributions}
\begin{Description}\relax
A collection and description of functions to compute 
density, distribution function, quantile function and 
to generate random variates for the skew normal, the skew 
Student-t, and skew generalized error distribution. In
addition maximum likelihood estimators are available to 
fit the parameters of a distribution and to compute 
basic statistical properties. 
\\

The functions are:

\Tabular{ll}{
\code{[dpqr]norm} & Normal distribution from R's base package, \\
\code{[dpqr]snorm} & Skew Normal distribution, \\
\code{[dpqr]std} & Symmetric Student-t Distribution, \\
\code{[dpqr]sstd} & Skew Student-t Distribution, \\
\code{[dpqr]ged} & Symmetric GED distribution, \\
\code{[dpqr]sged} & Skew GED distribution. }

The estimatore are:

\Tabular{ll}{
\code{normFit} & MLE parameter fit for a Normal distribution, \\
\code{snormFit} & MLE parameter fit for a skew Normal distribution, \\
\code{stdFit} & MLE parameter fit for a Sudent-t distribution, \\
\code{stdFit} & MLE parameter fit for a skew Sudent-t distribution, \\
\code{gedFit} & MLE parameter fit for a generalized error distribution, \\
\code{nigFit} & MLE parameter fit for a skew generalized error distribution. }

Utility Function:

\Tabular{ll}{
\code{absMoments} & Computes absolute moments of a symmetric density. }
\end{Description}
\begin{Usage}
\begin{verbatim}
dsnorm(x, mean = 0, sd = 1, xi = 1.5)
psnorm(q, mean = 0, sd = 1, xi = 1.5)
qsnorm(p, mean = 0, sd = 1, xi = 1.5)
rsnorm(n, mean = 0, sd = 1, xi = 1.5)

dstd(x, mean = 0, sd = 1, nu = 5)
pstd(q, mean = 0, sd = 1, nu = 5)
qstd(p, mean = 0, sd = 1, nu = 5)
rstd(n, mean = 0, sd = 1, nu = 5)

dsstd(x, mean = 0, sd = 1, nu = 5, xi = 1.5)
psstd(q, mean = 0, sd = 1, nu = 5, xi = 1.5)
qsstd(p, mean = 0, sd = 1, nu = 5, xi = 1.5)
rsstd(n, mean = 0, sd = 1, nu = 5, xi = 1.5)

dged(x, mean = 0, sd = 1, nu = 2)
pged(q, mean = 0, sd = 1, nu = 2)
qged(p, mean = 0, sd = 1, nu = 2)
rged(n, mean = 0, sd = 1, nu = 2)

dsged(x, mean = 0, sd = 1, nu = 2, xi = 1.5)
psged(q, mean = 0, sd = 1, nu = 2, xi = 1.5)
qsged(p, mean = 0, sd = 1, nu = 2, xi = 1.5)
rsged(n, mean = 0, sd = 1, nu = 2, xi = 1.5)

normFit(x, ...)
snormFit(x, ...)
stdFit(x, ...)
sstdFit(x, ...)
gedFit(x, ...)
sgedFit(x, ...)

absMoments(n, density = c("dnorm", "dged", "dstd"), ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{density}] [absMoments] - \\
a character string naming the symmetric density function.

\item[\code{mean, sd, nu, xi}] location parameter \code{mean},
scale parameter \code{sd},
shape parameter \code{nu}, 
skewness parameter \code{xi}.

\item[\code{n}] [rnorm][r*ged][r*std] - \\
the number of observations.\\{}
[absMoments] - \\
the number of absolute Moments.

\item[\code{p}] a numeric vector of probabilities.

\item[\code{x, q}] a numeric vector of quantiles.

\item[\code{...}] [*Fit] - \\
parameters parsed to the optimization function \code{nlm}.\\{}
[absMoments] - \\
parameters passed to the density function.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\bold{Symmetric Normal Distibution:}
\\\\
The functions for the normal distribution are part of R's
base package. The functions for the symmetric Student-t 
distribution are rescaled in such a way that they have unit 
variance in contrast to the Student-t family \code{dt}, \code{pt}, 
\code{qt} and \code{rt} which are part of R's base package.
The generalized error distribution functions are defined as 
described by Nelson (1991).
\\

\bold{Skew Normal Distribution:}
\\\\
The skew normal distribution functions are defined as described
by Fernandez and Steel (2000).
cr

\bold{Parameter Estimation:}
\\\\
The function \code{\LinkA{nlm}{nlm}} is used to minimize the "negative" maximum 
log-likelihood function. \code{nlm} carries out a minimization using 
a Newton-type algorithm.
\end{Details}
\begin{Value}
\code{d*} returns the density,
\code{p*} returns the distribution function,
\code{q*} returns the quantile function, and
\code{r*} generates random deviates, \\
all values are numeric vectors.

\code{*Fit} return a list with the following components: \\
\begin{ldescription}
\item[\code{estimate}] the point at which the maximum value of the log liklihood 
function is obtained.

\item[\code{objective}] the value of the estimated maximum, i.e. the value of the
log liklihood function.

\item[\code{message}] an integer indicating why the optimization process terminated.

\item[\code{code}] an integer indicating why the optimization process terminated.\\
1: relative gradient is close to zero, current iterate is probably 
solution; \\
2: successive iterates within tolerance, current iterate is probably 
solution; \\
3: last global step failed to locate a point lower than \code{estimate}. 
Either \code{estimate} is an approximate local minimum of the 
function or \code{steptol} is too small; \\
4: iteration limit exceeded; \\
5: maximum step size \code{stepmax} exceeded five consecutive times. 
Either the function is unbounded below, becomes asymptotic to a 
finite value from above in some direction or \code{stepmax} 
is too small.

\item[\code{gradient}] the gradient at the estimated maximum.

\item[\code{steps}] number of function calls.

\end{ldescription}


\code{absMoments} returns a numeric vector of length \code{n} with the
values of the absolute moments of the density function.
\end{Value}
\begin{Author}\relax
Diethelm Wuertz for the Rmetrics \R-port.
\end{Author}
\begin{References}\relax
Nelson D.B. (1991);
\emph{Conditional Heteroscedasticity in Asset Returns: A New Approach},
Econometrica, 59, 347--370.

Fernandez C., Steel M.F.J. (2000); 
\emph{On Bayesian Modelling of Fat Tails and Skewness},
Preprint, 31 pages.
\end{References}
\begin{Examples}
\begin{ExampleCode}
## SOURCE("fSeries.34A-GarchDistributions")

## snorm -
   xmpSeries("\nStart: Skew Normal Distribuion:  > ")
   par(mfrow = c(2, 2), cex = 0.75)
   set.seed(1953)
   r = rsnorm(n = 1000, mean = 1, sd = 0.5, xi = 1.5)
   plot(r, type = "l", main = "snorm: xi = 1.5")
   # Plot empirical density and compare with true density:
   hist(r, n = 25, probability = TRUE, border = "white", col = "steelblue4")
   x = seq(-4, 6, 0.1)
   lines(x, dsnorm(x = x, mean = 1, sd = 0.5, xi = 1.5))
   # Plot df and compare with true df:
   plot(sort(r), (1:1000/1000), main = "Probability", col = "steelblue4")
   lines(x, psnorm(x, mean = 1, sd = 0.5, xi = 1.5))
   # Compute quantiles:
   qsnorm(psnorm(q = -4:6, mean = 1, sd = 0.5, xi = 1.5), 
     mean = 1, sd = 0.5, xi = 1.5) 
     
## sstd -
   xmpSeries("\nStart: Skew Student-t Distribution:  > ")
   par(mfrow = c(2, 2), cex = 0.75)
   set.seed(1953)
   r = rsstd(n = 1000, nu = 4, xi = 1.5)
   # Print Variance:
   var(r)
   plot(r, type = "l", main = "sstd: xi = 1.5")
   # Plot empirical density and compare with true density:
   hist(r, n = 30, xlim = c(-5, 5), probability = TRUE, 
     border = "white", col = "steelblue4")
   x = seq(-5, 5, 0.1)
   lines(x, dsnorm(x = x, xi = 1.5))
   # Plot df and compare with true df:
   plot(sort(r), (1:1000/1000), main = "Probability", col = "steelblue4")
   lines(x, psstd(x, xi = 1.5))
   # Compute quantiles:
   qsstd(psstd(q = -5:5, xi = 1.5), xi = 1.5) 
   
## sged -
   xmpSeries("\nStart: Skew Generalized Error Distribuion:  > ")
   par(mfrow = c(2, 2), cex = 0.75)
   set.seed(1953)
   r = rsged(n = 1000, mean = 1, sd = 0.5, xi = 1.5)
   plot(r, type = "l", main = "sged: xi = 1.5")
   # Plot empirical density and compare with true density:
   hist(r, n = 25, probability = TRUE, border = "white", col = "steelblue4")
   x = seq(-1, 5, 0.1)
   lines(x, dsged(x = x, mean = 1, sd = 0.5, xi = 1.5))
   # Plot df and compare with true df:
   plot(sort(r), (1:1000/1000), main = "Probability", col = "steelblue4")
   lines(x, psged(x, mean = 1, sd = 0.5, xi = 1.5))
   # Compute quantiles:
   qsged(psged(q = -1:5, mean = 1, sd = 0.5, xi = 1.5), 
     mean = 1, sd = 0.5, xi = 1.5) 

## snormFit -
   xmpSeries("\nStart: MLE Fit to skew Normal Density > ")
   options(warn = -1) # suppress negative logs from nlm
   normFit(rnorm(1000))
   snormFit(rnorm(1000))
   
## sstdFit -
   xmpSeries("\nNext: MLE Fit to skew Student-t Density > ")
   sstdFit(rsstd(1000, mean = 1, sd = 1.5, nu = 7, xi = 2/3))
   
## sgedFit -
   xmpSeries("\nNext: MLE Fit to skew Generalized Error Density > ")
   sgedFit(rsged(1000, mean = -1, sd = 0.5, nu = 3, xi = 3/2),
         print.level = 2)
\end{ExampleCode}
\end{Examples}

