Skip to content

Finding the correlation coefficient of two stocks

2 messages · Dieter Menne, Pete Brecknock

#
veepsirtt wrote:
Check lenghts of your series. 


cor(c(1,2),c(1,2,3))

#Error in cor(c(1, 2), c(1, 2, 3)) : incompatible dimensions

Dieter
#
Dieter is correct, the lengths of the 2 series are different

Try ....

s = merge(s1,s2)

corr = cor(s[,"Close.s1"],s[,"Close.s2"],use="pairwise.complete.obs")

print(corr)

HTH

Pete