Accelerating the pace of engineering and science

# copulafit

Fit copula to data

## Syntax

RHOHAT = copulafit('Gaussian',U)
[RHOHAT,nuhat] = copulafit('t',U)
[RHOHAT,nuhat,nuci] = copulafit('t',U)
paramhat = copulafit('family',U)
[paramhat,paramci] = copulafit('family',U)
[...] = copulafit(...,'alpha',alpha)
[...] = copulafit('t',U,'Method','ApproximateML')
[...] = copulafit(...,'Options',options)

## Description

RHOHAT = copulafit('Gaussian',U) returns an estimate RHOHAT of the matrix of linear correlation parameters for a Gaussian copula, given data in U. U is an n-by-p matrix of values in the open interval (0,1) representing n points in the p-dimensional unit hypercube.

[RHOHAT,nuhat] = copulafit('t',U) returns an estimate RHOHAT of the matrix of linear correlation parameters for a t copula and an estimate nuhat of the degrees of freedom parameter, given data in U. U is an n-by-p matrix of values in the open interval (0,1) representing n points in the p-dimensional unit hypercube.

[RHOHAT,nuhat,nuci] = copulafit('t',U) also returns an approximate 95% confidence interval nuci for the degrees of freedom parameter estimated in nuhat.

paramhat = copulafit('family',U) returns an estimate paramhat of the copula parameter for an Archimedean copula specified by family, given data in U. U is an n-by-2 matrix of values in the open interval (0,1) representing n points in the unit square. family is one of Clayton, Frank, or Gumbel.

[paramhat,paramci] = copulafit('family',U) also returns an approximate 95% confidence interval paramci for the copula parameter estimated in paramhat.

[...] = copulafit(...,'alpha',alpha) returns approximate 100*(1-alpha)% confidence intervals in nuci or paramci.

 Note:   By default, copulafit uses maximum likelihood to fit a copula to U. When U contains data transformed to the unit hypercube by parametric estimates of their marginal cumulative distribution functions, this is known as the Inference Functions for Margins (IFM) method. When U contains data transformed by the empirical cdf (see ecdf), this is known as Canonical Maximum Likelihood (CML).

[...] = copulafit('t',U,'Method','ApproximateML') fits a t copula for large samples U by maximizing an objective function that approximates the profile log-likelihood for the degrees of freedom parameter (see [1]). This method can be significantly faster than maximum likelihood, but the estimates and confidence limits may not be accurate for small to moderate sample sizes.

[...] = copulafit(...,'Options',options) specifies control parameters for the iterative parameter estimation algorithm using an options structure options as created by statset. Type statset('copulafit') at the command prompt for fields and default values used by copulafit. This argument is not applicable to the 'Gaussian' family.

## Examples

expand all

### Fit a Gaussian Copula

Load and plot simulated stock return data.

```load stockreturns
x = stocks(:,1);
y = stocks(:,2);

figure;
scatterhist(x,y)
```

Transform the data to the copula scale (unit square) using a kernel estimator of the cumulative distribution function.

```u = ksdensity(x,x,'function','cdf');
v = ksdensity(y,y,'function','cdf');

figure;
scatterhist(u,v)
xlabel('u')
ylabel('v')
```

Fit a t copula.

```[Rho,nu] = copulafit('t',[u v],'Method','ApproximateML')
```
```Rho =

1.0000    0.7220
0.7220    1.0000

nu =

3.2780e+06

```

Generate a random sample from the t copula.

```r = copularnd('t',Rho,nu,1000);
u1 = r(:,1);
v1 = r(:,2);

figure;
scatterhist(u1,v1)
xlabel('u')
ylabel('v')
set(get(gca,'children'),'marker','.')
```

Transform the random sample back to the original scale of the data.

```x1 = ksdensity(x,u1,'function','icdf');
y1 = ksdensity(y,v1,'function','icdf');

figure;
scatterhist(x1,y1)
set(get(gca,'children'),'marker','.')
```

## References

[1] Bouye, E., V. Durrleman, A. Nikeghbali, G. Riboulet, and T. Roncalli. "Copulas for Finance: A Reading Guide and Some Applications." Working Paper. Groupe de Recherche Operationnelle, Credit Lyonnais, 2000.