2014年 米ドルとその他通貨及びゴールドとの各種相関

Data Source http://www.oanda.com/

Sys.time()
## [1] "2014-09-22 14:46:15 JST"

Package

#install.packages("knitr", dependencies=T)
#install.packages("quantmod", dependencies=T)
#install.packages("PerformanceAnalytics", dependencies=T)
library(knitr)
library(quantmod) # http://cran.r-project.org/web/packages/quantmod/quantmod.pdf
library(PerformanceAnalytics)

Import Data & Plot

username<-Sys.info()['user']
path01<-paste("C:/Users/",username,"/Desktop",sep="")
path02<-"R_output"
path<-file.path(path01,path02)
if(file.exists(path)==F){dir.create(path)}
FirstDate<-as.Date("2014/1/1")
LastDate<-as.Date("2014/9/19")
period<-1 #1:days 2:months
if(period==1){
period<-"days"
DateStyle<-"%Y/%b/%d"
}else
if(period==2){
period<-"months"
DateStyle<-"%Y/%b"  
}
location<-"oanda"
currency<-c("AUD","JPY","EUR","GBP","NZD","ZAR","CHF","CAD","XAU")
fx<-list()
allFx<-xts()
for(iii in 1:length(currency)){
pair=paste(currency[iii],"/USD",sep="") 
fx[[iii]]<-getSymbols(pair,src=location,auto.assign=FALSE,from=FirstDate) # ,to=LastDate
allFx<-merge(allFx,fx[[iii]])
}
head(allFx,1)
##                     AUD.USD  JPY.USD EUR.USD GBP.USD NZD.USD ZAR.USD
## 2014-01-01 09:00:00  0.8927 0.009521   1.379   1.652  0.8223 0.09553
##                     CHF.USD CAD.USD XAU.USD
## 2014-01-01 09:00:00   1.125  0.9399    1201
tail(allFx,1)
##                     AUD.USD  JPY.USD EUR.USD GBP.USD NZD.USD ZAR.USD
## 2014-09-22 09:00:00  0.8929 0.009174   1.283   1.629  0.8137 0.09045
##                     CHF.USD CAD.USD XAU.USD
## 2014-09-22 09:00:00   1.063  0.9125    1216

Plot

mtd=c("pearson","kendall","spearman")
for(iii in 1:length(mtd)){
chart.Correlation(allFx,method=mtd[iii],main=mtd[iii])
chart.Correlation(diff(allFx)[-1],method=mtd[iii],main=paste(mtd[iii],"1stDifference"))
}

plot of chunk unnamed-chunk-4plot of chunk unnamed-chunk-4plot of chunk unnamed-chunk-4plot of chunk unnamed-chunk-4plot of chunk unnamed-chunk-4plot of chunk unnamed-chunk-4