OFE correlation 1999-2011


/ Published in: R
Save to your folder(s)

data source: http://stooq.com


Copy this code and paste it in your HTML
  1. ofe_symbols <- c("aegn","alnz","aviv","axao","bnkw","gnrl",
  2. "ingn","nrda","pczt","peko","plst","pzuo",
  3. "wrta")
  4.  
  5. ofe_data <- list()
  6.  
  7. for (ofe_symbol in ofe_symbols) {
  8.  
  9. ofe_data[[ofe_symbol]] <- read.csv(paste(ofe_symbol,"_ofe_d.csv",sep=""),head=TRUE)
  10.  
  11. colnames(ofe_data[[ofe_symbol]]) <- c("date","open","high","low","close")
  12.  
  13. }
  14.  
  15. # wszystkie daty wystepujace w danych
  16. dates <- sort(unique(unlist(lapply(ofe_data,function(x) as.character(x[,"date"])))))
  17.  
  18. # zestawiamy notowania wedlug dat
  19. price_matrix <- do.call(cbind,
  20. lapply(ofe_data,
  21.  
  22. function(x) {
  23.  
  24. dummy <- rep(NA,length(dates))
  25.  
  26. matching_dates <- match(x[,"date"],dates)
  27.  
  28. dummy[matching_dates] <- x[,"close"]
  29.  
  30. dummy
  31.  
  32. })
  33. )
  34.  
  35. # zestawienie notowan OFE:
  36. matplot(price_matrix,type="l",lty="solid",main="notowania OFE 1999-2011")
  37.  
  38. x <- cor(price_matrix,use="complete.obs")
  39.  
  40. y <- NA
  41.  
  42. for (i in 1:(length(ofe_symbols)-1)) {
  43. for (j in (i+1):length(ofe_symbols)) {
  44. y <- c(y,x[i,j])
  45. }
  46. }
  47.  
  48. y <- y[-1]
  49.  
  50. # wykres gestosci rozkladu wsp. korelacji:
  51. plot(density(y),type="l",main="Rozklad wsp. korelacji miedzy OFE")
  52. abline(v=mean(y),col="Orange",lty="dotted")
  53. title(paste("range = ",paste(format(range(y),digits=4),collapse=" ")),font.main=1,cex.main=0.8,line=1)

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.