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. (xi - µx) and (yi - µy)
- Multiply deviation of x corresponding deviation of y i.e. (xi - µx) × (yi - µy)
- Sum up all the products of deviations
- Divide by total number of observations N.
Formula
The following equation describes the relationship:
$$ \text{Cov}(\text{x} \text{,} \text{y})=\sum _ {\text{i}}^{\text{N}}\frac{(\text{x}\ -\ \mu _ \text{x})(\text{y}\ -\ \mu _ \text{y})}{\text{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:
$$ \text{Cov}(\text{x} \text{,} \text{y})=\rho\times\sigma _ \text{x}\times\sigma _ \text{y} $$
Where ρ is the correlation coefficient, \sigmax is the standard deviation of x and \sigmay 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 |
$$ \text{Mean} \text{of} \text{x} = \ \mu _ \text{x} = \text{63.83} $$
$$ \text{Mean} \text{of} \text{y} = \ \mu _ \text{y} = \text{45.34} $$
$$ \text{Sum of products of deviations} = (\text{x}\ -\ \mu _ \text{x})(\text{y}\ -\ \mu _ \text{y}) = \text{16,467} $$
$$ \text{Cov}(\text{x} \text{,} \text{y})=\sum _ {\text{i}}^{\text{N}}{\frac{\text{16,467}}{\text{48}}=\text{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.
$$ \text{Cov}(\text{x} \text{,} \text{y})=\text{0.93}\times\text{23.63}\times\text{15.87}=\text{343} $$
by Obaidullah Jan, ACA, CFA and last modified on