# Finding the correlation coefficient of two stocks

6 messages
Open this post in threaded view
|

## Finding the correlation coefficient of two stocks

 This post has NOT been accepted by the mailing list yet. Hi , library(tseries) years <- 2 n <- 50 today <- Sys.Date()     s1 <- get.hist.quote(instrument = "^BSESN", start = format(today-365*years-2*n),quote = "Close") s2 <- get.hist.quote(instrument = "BHEL.BO", start = format(today-365*years-2*n),quote = "Close") corr <- cor(s1,s2) print(corr) While Running the above commands i got the following errors corr <- cor(s1,s2) Error in cor(s1, s2) : incompatible dimensions so I am no table to find the correlation coefficient of the above stocks. Kindly help me thanks veepsirtt
Open this post in threaded view
|

## Re: Finding the correlation coefficient of two stocks

 veepsirtt wrote corr <- cor(s1,s2) Error in cor(s1, s2) : incompatible dimensions 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
Open this post in threaded view
|

## Re: Finding the correlation coefficient of two stocks

 This post has NOT been accepted by the mailing list yet. Hi Dieter Menne, Yahoo historical stock price contains " Zeros and NA" for my symbols "^BSESN","BHEL.BO"  . I want to remove  " Zeros and NA" so that the dimensions of both the series  is the same. How to do it ?. thanks veepsirtt
Open this post in threaded view
|

## Re: Finding the correlation coefficient of two stocks

 In reply to this post by Dieter Menne 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