# NAG Library Function Document

## 1Purpose

nag_estim_gen_pareto (g07bfc) estimates parameter values for the generalized Pareto distribution by using either moments or maximum likelihood.

## 2Specification

 #include #include
 void nag_estim_gen_pareto (Integer n, const double y[], Nag_OptimOpt optopt, double *xi, double *beta, double asvc[], double obsvc[], double *ll, NagError *fail)

## 3Description

Let the distribution function of a set of $n$ observations
 $yi , i=1,2,…,n$
be given by the generalized Pareto distribution:
 $Fy = 1- 1+ ξy β -1/ξ , ξ≠0 1-e-yβ , ξ=0;$
where
• $\beta >0$ and
• $y\ge 0$, when $\xi \ge 0$;
• $0\le y\le -\frac{\beta }{\xi }$, when $\xi <0$.
Estimates $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$ of the parameters $\xi$ and $\beta$ are calculated by using one of:
• method of moments (MOM);
• probability-weighted moments (PWM);
• maximum likelihood estimates (MLE) that seek to maximize the log-likelihood:
 $L = -n ln⁡ β^ - 1+ 1ξ^ ∑ i=1 n ln 1+ ξ^yi β^ .$
The variances and covariance of the asymptotic Normal distribution of parameter estimates $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$ are returned if $\stackrel{^}{\xi }$ satisfies:
• $\stackrel{^}{\xi }<\frac{1}{4}$ for the MOM;
• $\stackrel{^}{\xi }<\frac{1}{2}$ for the PWM method;
• $\stackrel{^}{\xi }<-\frac{1}{2}$ for the MLE method.
If the MLE option is exercised, the observed variances and covariance of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$ is returned, given by the negative inverse Hessian of $L$.

## 4References

Hosking J R M and Wallis J R (1987) Parameter and quantile estimation for the generalized Pareto distribution Technometrics 29(3)
McNeil A J, Frey R and Embrechts P (2005) Quantitative Risk Management Princeton University Press

## 5Arguments

1:    $\mathbf{n}$IntegerInput
On entry: the number of observations.
Constraint: ${\mathbf{n}}>1$.
2:    $\mathbf{y}\left[{\mathbf{n}}\right]$const doubleInput
On entry: the $n$ observations ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, assumed to follow a generalized Pareto distribution.
Constraints:
• ${\mathbf{y}}\left[i-1\right]\ge 0.0$;
• $\sum _{\mathit{i}=1}^{n}{\mathbf{y}}\left[i-1\right]>0.0$.
3:    $\mathbf{optopt}$Nag_OptimOptInput
On entry: determines the method of estimation, set:
${\mathbf{optopt}}=\mathrm{Nag_PWM}$
For the method of probability-weighted moments.
${\mathbf{optopt}}=\mathrm{Nag_MOM}$
For the method of moments.
${\mathbf{optopt}}=\mathrm{Nag_MOMMLE}$
For maximum likelihood with starting values given by the method of moments estimates.
${\mathbf{optopt}}=\mathrm{Nag_PWMMLE}$
For maximum likelihood with starting values given by the method of probability-weighted moments.
Constraint: ${\mathbf{optopt}}=\mathrm{Nag_PWM}$, $\mathrm{Nag_MOM}$, $\mathrm{Nag_MOMMLE}$ or $\mathrm{Nag_PWMMLE}$.
4:    $\mathbf{xi}$double *Output
On exit: the parameter estimate $\stackrel{^}{\xi }$.
5:    $\mathbf{beta}$double *Output
On exit: the parameter estimate $\stackrel{^}{\beta }$.
6:    $\mathbf{asvc}\left[4\right]$doubleOutput
On exit: the variance-covariance of the asymptotic Normal distribution of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$. ${\mathbf{asvc}}\left[0\right]$ contains the variance of $\stackrel{^}{\xi }$; ${\mathbf{asvc}}\left[3\right]$ contains the variance of $\stackrel{^}{\beta }$; ${\mathbf{asvc}}\left[1\right]$ and ${\mathbf{asvc}}\left[2\right]$ contain the covariance of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$.
7:    $\mathbf{obsvc}\left[4\right]$doubleOutput
On exit: if maximum likelihood estimates are requested, the observed variance-covariance of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$. ${\mathbf{obsvc}}\left[0\right]$ contains the variance of $\stackrel{^}{\xi }$; ${\mathbf{obsvc}}\left[3\right]$ contains the variance of $\stackrel{^}{\beta }$; ${\mathbf{obsvc}}\left[1\right]$ and ${\mathbf{obsvc}}\left[2\right]$ contain the covariance of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$.
8:    $\mathbf{ll}$double *Output
On exit: if maximum likelihood estimates are requested, ll contains the log-likelihood value $L$ at the end of the optimization; otherwise ll is set to $-1.0$.
9:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}>1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_OPTIMIZE
The optimization of log-likelihood failed to converge; no maximum likelihood estimates are returned. Try using the other maximum likelihood option by resetting optopt. If this also fails, moments-based estimates can be returned by an appropriate setting of optopt.
Variance of data in y is too low for method of moments optimization.
NE_REAL_ARRAY
On entry, ${\mathbf{y}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{y}}\left[i-1\right]\ge 0.0$ for all $i$.
NE_ZERO_SUM
The sum of y is zero within machine precision.
NW_PARAM_DIST
The asymptotic distribution of parameter estimates is invalid and the distribution of maximum likelihood estimates cannot be calculated for the returned parameter estimates because the Hessian matrix could not be inverted.
NW_PARAM_DIST_ASYM
The asymptotic distribution is not available for the returned parameter estimates.
NW_PARAM_DIST_OBS
The distribution of maximum likelihood estimates cannot be calculated for the returned parameter estimates because the Hessian matrix could not be inverted.

Not applicable.

## 8Parallelism and Performance

nag_estim_gen_pareto (g07bfc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_estim_gen_pareto (g07bfc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The search for maximum likelihood parameter estimates is further restricted by requiring
 $1+ ξ^yi β^ > 0 ,$
as this avoids the possibility of making the log-likelihood $L$ arbitrarily high.

## 10Example

This example calculates parameter estimates for $23$ observations assumed to be drawn from a generalized Pareto distribution.

### 10.1Program Text

Program Text (g07bfce.c)

### 10.2Program Data

Program Data (g07bfce.d)

### 10.3Program Results

Program Results (g07bfce.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017