Lesson 4 of 15
Covariance & Correlation
Covariance & Correlation
Covariance measures how two variables move together. A positive covariance means they tend to move in the same direction; negative means opposite.
Sample covariance between and :
Pearson Correlation normalizes covariance to the range :
where and are the sample standard deviations.
A correlation of 1 means perfect positive linear relationship, -1 means perfect inverse, and 0 means no linear relationship.
In portfolio construction, correlation determines diversification benefit: assets with low or negative correlation reduce portfolio volatility.
Your Task
Implement:
covariance(xs, ys)— sample covariancecorrelation(xs, ys)— Pearson correlation coefficient
Python runtime loading...
Loading...
Click "Run" to execute your code.