Accelerating the pace of engineering and science

# cov

Covariance matrix

## Syntax

```cov(X)
cov(X,Y)
```

## Arguments

 X Financial times series object. Y Financial times series object.

## Description

cov for financial time series objects is based on the MATLAB® cov function. See cov in the MATLAB documentation.

If X is a financial time series object with one series, cov(X) returns the variance. For a financial time series object containing multiple series, where each row is an observation, and each series a variable, cov(X) is the covariance matrix.

diag(cov(X)) is a vector of variances for each series and sqrt(diag(cov(X))) is a vector of standard deviations.

cov(X, Y), where X and Y are financial time series objects with the same number of elements, is equivalent to cov([X(:) Y(:)]).

cov(X) or cov(X, Y) normalizes by (N -1) if N > 1, where N is the number of observations. This makes cov(X) the best unbiased estimate of the covariance matrix if the observations are from a normal distribution. For N = 1, cov normalizes by N.

cov(X, 1) or cov(X, Y, 1) normalizes by N and produces the second moment matrix of the observations about their mean. cov(X, Y, 0) is the same as cov(X, Y) and cov(X, 0) is the same as cov(X). The mean is removed from each column before calculating the result.

## Examples

expand all

### Create a Covariance Matrix

This example shows how to create a covariance matrix for the following dates.

```dates = {'01-Jan-2007';'02-Jan-2007';'03-Jan-2007'};
A = [-1 1 2 ; -2 3 1 ; 4 0 3];
f = fints(dates, A);

c = cov(f)
```
```c =

10.3333   -4.1667    3.0000
-4.1667    2.3333   -1.5000
3.0000   -1.5000    1.0000

```