WIG20 - S&P500 day-to-day correlation


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



Copy this code and paste it in your HTML
  1. fw20 <- read.csv("fw20_d.csv")
  2. esf <- read.csv("es_f_d.csv")
  3.  
  4. nrow(fw20); nrow(esf)
  5.  
  6. D_Change <- log(esf$Close[-1]/esf$Close[-nrow(esf)])
  7.  
  8. esfc <- cbind(esf[2:nrow(esf),],D_Change)
  9.  
  10. D_Change <- log(fw20$Close[-1]/fw20$Close[-nrow(fw20)])
  11. OC_Change <- log(fw20$Close/fw20$Open)[2:nrow(fw20)]
  12.  
  13. fw20c <- cbind(fw20[2:nrow(fw20),],D_Change,OC_Change)
  14.  
  15. dates <- function(x) {
  16.  
  17. strptime(x$Date,"%Y-%m-%d")
  18.  
  19. }
  20.  
  21. fw20c <- fw20c[which(!is.na(match(as.numeric(dates(fw20c))-86400,as.numeric(dates(esfc))))),]
  22.  
  23. esfc <- esfc[which(!is.na(match(as.numeric(dates(esfc))+86400,as.numeric(dates(fw20c))))),]
  24.  
  25. nrow(fw20c); nrow(esfc)
  26.  
  27. fw20c[1:10,]
  28.  
  29. esfc[1:10,]
  30.  
  31. cor(esfc$D_Change,fw20c$D_Change)
  32. cor(esfc$D_Change,fw20c$OC_Change)
  33. cor(fw20c$D_Change,fw20c$OC_Change)

URL: http://www.reakkt.com/2011/10/correlation-doesnt-mean-easy-prediction.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.