How Do You Calculate Stock Correlation Coefficient?
• Begin with a set of n stock returns, for two stocks X and Y: X1, X2, … Xn and Y1, Y2, … Yn • Calculate the mean of each set: Mx = (X1 + X2 + … + Xn)/n My = (Y1 + Y2 + … + Yn)/n • Calculate the covariance: COVAR = { (X1-Mx)(Y1-My) + (X2-Mx)(Y2-My) + …+ (Xn-Mx)(Yn-My) }/n • Calculate the variance of each stock: Vx = { (X1-Mx)2 + (X2-Mx)2 + … +(Xn-Mx)2 } / n Vy = { (Y1-My)2 + (Y2-My)2 + … +(Yn-My)2 } / n • The standard deviation is the square root of the variance: Sx = SQRT(Vx) Sy = SQRT(Vy) • Finally, the Pearson correlation coefficient: Correlation = COVAR / ( Sx Sy) • br>Plot the pairs to obtain a scatter plot. Plot the pairs to obtain a scatter plot. (X1,Y1), (X2,Y2), … (Xn,Yn). Note some other properties of the data. • The best fit line to the data is called the regression line. • The correlation is a measure of how closely the two stock returns are related, linearly. That is, how closely the return values satisfy a linear relation such as Y = βX + α for some consta