# Covariance

Covariance measures the extent to which two variables, say x and y, move together. A positive covariance means that the variables move in tandem and a negative value indicates that the variables have an inverse relationship. While covariance can indicate the direction of relation, the correlation coefficient is a better measure of the strength of relationship.

Covariance is an important input in estimation of diversification benefits and portfolio optimization, calculation of beta coefficient, etc.

In manual calculation of covariance, the following steps are involved:

- Calculate mean of each variable i.e. µ
_{x}and µ_{x}, - Find deviation of each value of x and y from their respective means i.e. (x
_{i}- µ_{x}) and (y_{i}- µ_{y}) - Multiply deviation of x corresponding deviation of y i.e. (x
_{i}- µ_{x}) × (y_{i}- µ_{y}) - Sum up all the products of deviations
- Divide by total number of observations N.

## Formula

The following equation describes the relationship:

$$ Cov(x,y)=\sum_{i}^{N}\frac{(x\ -\ \mu_x)(y\ -\ \mu_y)}{N} $$

Covariance can also be calculated using Excel COVAR, COVARIANCE.P and COVARIANCE.S functions.

If we know the correlation coefficient, we can work out covariance indirectly as follows:

$$ Cov(x,y)=\rho\times\sigma_x\times\sigma_y $$

Where ρ is the correlation coefficient, \sigma*x is the standard deviation of x and \sigma*y is the standard deviation of y.

## Example

Let’s calculate covariance using the same data set as in correlation coefficient.

The data set bellows shows monthly closing prices of SPDR Oil & Gas Exploration and Production ETF (designed as y) and Brent Crude (designed as x):

Date | x | y |
---|---|---|

1/1/2014 | 109.95 | 65.75 |

2/1/2014 | 108.16 | 69.69 |

3/1/2014 | 108.98 | 71.83 |

4/1/2014 | 105.7 | 77.61 |

5/1/2014 | 108.63 | 77.04 |

6/1/2014 | 109.21 | 82.28 |

7/1/2014 | 110.84 | 75.29 |

8/1/2014 | 103.45 | 79.05 |

9/1/2014 | 101.12 | 68.83 |

10/1/2014 | 94.57 | 60.87 |

11/1/2014 | 84.17 | 51.08 |

12/1/2014 | 70.87 | 47.86 |

1/1/2015 | 55.27 | 46.18 |

2/1/2015 | 47.52 | 50.81 |

3/1/2015 | 61.89 | 51.66 |

4/1/2015 | 55.73 | 55.09 |

5/1/2015 | 64.13 | 49.53 |

6/1/2015 | 64.88 | 46.66 |

7/1/2015 | 62.01 | 38.35 |

8/1/2015 | 52.21 | 36.00 |

9/1/2015 | 49.56 | 32.84 |

10/1/2015 | 47.69 | 36.61 |

11/1/2015 | 49.56 | 37.13 |

12/1/2015 | 44.44 | 30.22 |

1/1/2016 | 37.28 | 28.49 |

2/1/2016 | 34.24 | 24.60 |

3/1/2016 | 36.81 | 30.35 |

4/1/2016 | 38.67 | 35.74 |

5/1/2016 | 48.13 | 35.52 |

6/1/2016 | 49.72 | 34.81 |

7/1/2016 | 50.35 | 34.25 |

8/1/2016 | 42.14 | 36.79 |

9/1/2016 | 45.45 | 38.46 |

10/1/2016 | 49.06 | 35.35 |

11/1/2016 | 48.14 | 41.93 |

12/1/2016 | 53.94 | 43.18 |

1/1/2017 | 56.82 | 40.08 |

2/1/2017 | 56.8 | 37.86 |

3/1/2017 | 56.36 | 37.44 |

4/1/2017 | 52.83 | 34.95 |

5/1/2017 | 51.52 | 32.57 |

6/1/2017 | 50.63 | 31.92 |

7/1/2017 | 47.92 | 32.52 |

8/1/2017 | 51.78 | 30.16 |

9/1/2017 | 52.75 | 34.09 |

10/1/2017 | 57.54 | 34.28 |

11/1/2017 | 60.49 | 35.72 |

12/1/2017 | 63.73 | 37.18 |

$$ Mean of x = \ \mu_x = 63.83 $$

$$ Mean of y = \ \mu_y = 45.34 $$

$$ Sum\ of\ products\ of\ deviations = (x\ -\ \mu_x)(y\ -\ \mu_y) = 16,467 $$

$$ Cov(x,y)=\sum_{i}^{N}{\frac{16,467}{48}=343.06} $$

Covariance of SPDR XOP ETF with Brent Crude is positive which indicates that they both move together. However, we can’t say conclusively how strong the relationship because the covariance value depends on the units used. Correlation coefficient is a better measure which works out to 0.93 for the given data set. We can arrive at covariance value if we have the value for correlation coefficient and individual standard deviations of x and y, which are 23.63 and 15.87 respectively.

$$ Cov(x,y)=0.93\times23.63\times15.87=343 $$

Written by Obaidullah Jan