G07 Chapter Contents
G07 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG07BFF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G07BFF estimates parameter values for the generalized Pareto distribution by using either moments or maximum likelihood.

## 2  Specification

 SUBROUTINE G07BFF ( N, Y, OPTOPT, XI, BETA, ASVC, OBSVC, LL, IFAIL)
 INTEGER N, OPTOPT, IFAIL REAL (KIND=nag_wp) Y(N), XI, BETA, ASVC(4), OBSVC(4), LL

## 3  Description

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$.

## 4  References

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

## 5  Parameters

1:     $\mathrm{N}$ – INTEGERInput
On entry: the number of observations.
Constraint: ${\mathbf{N}}>1$.
2:     $\mathrm{Y}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
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\right)\ge 0.0$;
• $\sum _{\mathit{i}=1}^{n}{\mathbf{Y}}\left(i\right)>0.0$.
3:     $\mathrm{OPTOPT}$ – INTEGERInput
On entry: determines the method of estimation, set:
${\mathbf{OPTOPT}}=-2$
For the method of probability-weighted moments.
${\mathbf{OPTOPT}}=-1$
For the method of moments.
${\mathbf{OPTOPT}}=1$
For maximum likelihood with starting values given by the method of moments estimates.
${\mathbf{OPTOPT}}=2$
For maximum likelihood with starting values given by the method of probability-weighted moments.
Constraint: ${\mathbf{OPTOPT}}=-2$, $-1$, $1$ or $2$.
4:     $\mathrm{XI}$ – REAL (KIND=nag_wp)Output
On exit: the parameter estimate $\stackrel{^}{\xi }$.
5:     $\mathrm{BETA}$ – REAL (KIND=nag_wp)Output
On exit: the parameter estimate $\stackrel{^}{\beta }$.
6:     $\mathrm{ASVC}\left(4\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the variance-covariance of the asymptotic Normal distribution of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$. ${\mathbf{ASVC}}\left(1\right)$ contains the variance of $\stackrel{^}{\xi }$; ${\mathbf{ASVC}}\left(4\right)$ contains the variance of $\stackrel{^}{\beta }$; ${\mathbf{ASVC}}\left(2\right)$ and ${\mathbf{ASVC}}\left(3\right)$ contain the covariance of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$.
7:     $\mathrm{OBSVC}\left(4\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: if maximum likelihood estimates are requested, the observed variance-covariance of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$. ${\mathbf{OBSVC}}\left(1\right)$ contains the variance of $\stackrel{^}{\xi }$; ${\mathbf{OBSVC}}\left(4\right)$ contains the variance of $\stackrel{^}{\beta }$; ${\mathbf{OBSVC}}\left(2\right)$ and ${\mathbf{OBSVC}}\left(3\right)$ contain the covariance of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$.
8:     $\mathrm{LL}$ – REAL (KIND=nag_wp)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:     $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{N}}>1$.
${\mathbf{IFAIL}}=2$
On entry, ${\mathbf{Y}}\left(〈\mathit{\text{value}}〉\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{Y}}\left(i\right)\ge 0.0$ for all $i$.
${\mathbf{IFAIL}}=3$
On entry, ${\mathbf{OPTOPT}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{OPTOPT}}=-2$, $-1$, $1$ or $2$.
${\mathbf{IFAIL}}=6$
The asymptotic distribution is not available for the returned parameter estimates.
${\mathbf{IFAIL}}=7$
The distribution of maximum likelihood estimates cannot be calculated for the returned parameter estimates because the Hessian matrix could not be inverted.
${\mathbf{IFAIL}}=8$
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.
${\mathbf{IFAIL}}=9$
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.
${\mathbf{IFAIL}}=10$
Variance of data in Y is too low for method of moments optimization.
${\mathbf{IFAIL}}=11$
The sum of Y is zero within machine precision.
${\mathbf{IFAIL}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

Not applicable.

## 8  Parallelism and Performance

G07BFF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

## 9  Further Comments

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.

## 10  Example

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

### 10.1  Program Text

Program Text (g07bffe.f90)

### 10.2  Program Data

Program Data (g07bffe.d)

### 10.3  Program Results

Program Results (g07bffe.r)