Return to Snippet

Revision: 54808
at January 12, 2012 18:35 by mjaniec


Initial Code
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 danych
dates <- sort(unique(unlist(lapply(ofe_data,function(x) as.character(x[,"date"])))))

# zestawiamy notowania wedlug dat
price_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)

Initial URL
http://www.reakkt.com/2012/01/some-thoughts-on-polish-pension-funds.html

Initial Description
data source: http://stooq.com

Initial Title
OFE correlation 1999-2011

Initial Tags


Initial Language
R