1. Covariance and correlation
2. Stock prices for stock A
Let's again consider a time series of two hypothetical stock prices, from companies A and B, as shown in the figure. The estimated mean stock price for company A over this time period is about 32, and it's standard deviation is about 1-point-8, as found using the sd() function in R.
3. Stock prices for stock B
For company B, its mean was also about 32, while its standard deviation was about 2-point-2.
4. Covariance of stock A and B
In R, you apply the cov() function to estimate the covariance between the stock prices of companies A and B, paired by time. It's about 2-point-86. A positive covariance implies a positive association between the prices, as is apparent in the scatterplot. Covariance depends on the scale of the variables, so it is hard to interpret whether 2-point-86 is a relatively small or large value.
5. Correlations
Correlations are a standardized version of covariance that do not depend on the scale of the variables. Recall that correlations are always between minus 1 and positive 1. A correlation of positive 1 indicates a perfect positive or upward linear (straight line) relationship between two variables, while a correlation of negative 1 indicates a perfect negative of downward linear (straight line) relationship between two variables. A correlation of zero indicates no linear association between the variables, although they may still have a nonlinear association.
6. Correlation of stock A and B
In R, you apply the cor() function to estimate the correlation between the stock prices of companies A and B, paired by time. Of course, the correlation is simply the covariance divided by the standard deviation of each variable. In either case, it's estimated to be 0-point-71, which indicates a moderately strong positive linear relationship between the variables. This matches what we see in the scatterplot: there is moderate variation about a positive or upward sloping (straight line) trend.
7. Covariance and correlation: log returns
Instead of stock prices, let's compare the log returns for this pair of stocks. Log returns are not on the same scale as prices, and the estimated covariance value of 0-point-001 is much smaller than before.
8. Covariance and correlation: log returns
However, as you can see from the scatterplot of the log returns in the figure on the right, there is clearly a positive association between them. This is apparent when you estimate their correlation, which is found to be 0-point-74.
9. Let's practice!
Good work! Now you practice calculating covariances and correlations.