2
$\begingroup$

I am trying to find out if there is a relation between 5 different stock markets rates over a period of 5 years.

I was advised by my supervisor to use the Concordance Correlation Coefficient which unfortunately I have not studied and I am unsure how to proceed. I was also advised to use Timeseries on the data.

$\endgroup$

1 Answer 1

2
$\begingroup$

I'm not sure what "Concordance Correlation" is, but you can start by examining regular correlation, as well as how that correlation changes over time. You may also want to examine whether or not the series are cointegrated. Here's some example code for the last category.

Here's a quick example of how you might do the above with 5 stocks in R. I'm not sure what you meant by "rates," so I just used log of daily closing price.

#Load daily closing prices for various stock
library(quantmod)
stocks <- c('AAPL','MSFT','GOOG','YHOO','CSCO')
getSymbols(stocks)
myData <- do.call(cbind,list(Cl(AAPL),Cl(MSFT),Cl(GOOG),Cl(YHOO),Cl(CSCO)))
names(myData) <- stocks

#Convert from prices to log prices
myData <- apply(myData,2,function(x) log(x))

#Look at correlations
library(PerformanceAnalytics)
chart.Correlation(myData)

Corr1

#Look at correlations over time
getSymbols('SPY')
SP500 <- log(Cl(SPY))
chart.RollingCorrelation(myData, SP500, legend.loc="bottomleft",
 main = "Rolling 90-day Correlation",width=90)

Corr2

#Look at cointegration
#Reference: http://quanttrader.info/public/testForCoint.html
testCI <- function(name1,name2) {
    stopifnot(require(tseries))

    fmla <- as.formula(paste(name1, "~", name2,'+0'))

    m <- lm(fmla, data=)
    beta <- coef(m)[1]

    sprd <- myData[,name1] - beta*myData[,name2] 
    ht <- adf.test(sprd, alternative="stationary", k=0)

    CI <- ifelse(ht$p.value<=0.05,'Yes','No')

    return(data.frame(Hedge.Ratio=beta, ADF.p.value=ht$p.value, Cointegrated=CI))
}
library(plyr)
Pairs <- data.frame(t(combn(stocks,2)))
ddply(Pairs,c('X1','X2'),function(x) testCI(x$X1,x$X2))

Result:

     X1   X2 Hedge.Ratio ADF.p.value Cointegrated
1  AAPL CSCO 10.25392901  0.67231061           No
2  AAPL GOOG  0.22279512  0.64603831           No
3  AAPL MSFT  7.96509377  0.50827930           No
4  AAPL YHOO -3.53723462  0.48582217           No
5  GOOG CSCO 18.74785464  0.66816834           No
6  GOOG YHOO -2.46708417  0.42749297           No
7  MSFT CSCO  0.57717372  0.04188564          Yes
8  MSFT GOOG -0.02110384  0.57239123           No
9  MSFT YHOO -0.51397517  0.60290222           No
10 YHOO CSCO  0.29471326  0.08929770           No
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.