## Posted By

mjaniec on 01/12/12

# OFE correlation 1999-2011

/ Published in: R

data source: http://stooq.com

`ofe_symbols <- c("aegn","alnz","aviv","axao","bnkw","gnrl",                 "ingn","nrda","pczt","peko","plst","pzuo",                  "wrta") ofe_data <- list() for (ofe_symbol in ofe_symbols) {   ofe_data[[ofe_symbol]] <- read.csv(paste(ofe_symbol,"_ofe_d.csv",sep=""),head=TRUE)   colnames(ofe_data[[ofe_symbol]]) <- c("date","open","high","low","close") } # wszystkie daty wystepujace w danychdates <- sort(unique(unlist(lapply(ofe_data,function(x) as.character(x[,"date"]))))) # zestawiamy notowania wedlug datprice_matrix <- do.call(cbind,                        lapply(ofe_data,                              function(x) {                                dummy <- rep(NA,length(dates))                              matching_dates <- match(x[,"date"],dates)                              dummy[matching_dates] <- x[,"close"]                              dummy                             })                        ) # zestawienie notowan OFE:matplot(price_matrix,type="l",lty="solid",main="notowania OFE 1999-2011") x <- cor(price_matrix,use="complete.obs") y <- NA for (i in 1:(length(ofe_symbols)-1)) {  for (j in (i+1):length(ofe_symbols)) {      y <- c(y,x[i,j])  }}  y <- y[-1] # wykres gestosci rozkladu wsp. korelacji:plot(density(y),type="l",main="Rozklad wsp. korelacji miedzy OFE")abline(v=mean(y),col="Orange",lty="dotted")title(paste("range = ",paste(format(range(y),digits=4),collapse=" ")),font.main=1,cex.main=0.8,line=1)`