Sys.time()

[1] “2014-10-27 17:22:44 JST”

cnt<-0 #index no for dataset
dataset<-list()
ts.source<-list()
##import by quantmod
ts.source[[1]]<-c("yahoo",4,"^N225","^HSI","^AXJO","^GSPC","NDX","^RUT","^FTSE")
ts.source[[2]]<-c("yahoo",4,"^STI","^KS11","^TWII","^GDAXI","^FCHI")
ts.source[[3]]<-c("FRED",1,"DCOILWTICO","GOLDAMGBD228NLBM","DEXJPUS","DGS10")
ts.source[[4]]<-c("FRED",1,"DEXUSEU","DEXUSAL","DEXUSUK")
ts.source[[5]]<-c("oanda",1,"XAU","XAG","XPT","XPD")
ts.source[[6]]<-c("oanda",1,"AUD","NZD","ZAR","CAD","NOK")#,"SAR","AED")
ts.source[[7]]<-c("oanda",1,"BRL","RUB","IDR","CNY")
ts.source[[8]]<-c("oanda",1,"SGD","CLP","BND","VND","PEN","MYR","MXN","JPY")
ts.source[[9]]<-c("oanda",1,"BTC","EUR")
ts.source[[10]]<-c("FRED",1,"DFF","BAMLH0A0HYM2","DTB3","DAAA","DBAA")
ts.source[[11]]<-c("FRED",1,"DTWEXM","SP500","DFII10")
ts.source[[12]]<-c("yahoo",4,"^BVSP","000001.SS")
for(lll in 1:length(ts.source)){
for(iii in 3:length(ts.source[[lll]])){
cnt<-cnt+1
if(ts.source[[lll]][1]=="oanda"){
item<-paste(ts.source[[lll]][iii],"/USD",sep="") 
}
else{
item<- ts.source[[lll]][iii]
}
dataset[[cnt]]<-getSymbols(item,src=ts.source[[lll]][1],auto.assign=FALSE)
dataset[[cnt]]<-dataset[[cnt]][,as.double(ts.source[[lll]][2])]
}
}
##nikkei,TODAIDailyPriceIndex as data frame
url<-c(
"http://www.cmdlab.co.jp/price_u-tokyo/download/HistoricalDailyData.csv",
"http://indexes.nikkei.co.jp/nkave/historical/nikkei_stock_average_daily_en.csv"
)
for(iii in 1:length(url)){
cnt<-cnt+1
dataset[[cnt]]<-read.csv(url[iii],header=T,skip=0,stringsAsFactor=F)
dataset[[cnt]][,1]<-as.Date(dataset[[cnt]][,1])
if(grepl("nikkei",url[iii])==T){
colnames(dataset[[cnt]])<-paste("Nikkei.",colnames(dataset[[cnt]]),sep="")
}
}
##Japanese Government Bonds as data frame
cnt<-cnt+1
url<-c(
"http://www.mof.go.jp/english/jgbs/reference/interest_rate/historical/jgbcme_all.csv",
"http://www.mof.go.jp/english/jgbs/reference/interest_rate/jgbcme.csv"
)
dataset[[cnt]]<-rbind(read.csv(url[1],header=T,skip=0,stringsAsFactor=F),read.csv(url[2],header=T,skip=0,stringsAsFactor=F))
dataset[[cnt]][,1]<-as.Date(dataset[[cnt]][,1])
FUN.1<-function(x) as.numeric(x)
dataset[[cnt]]<-cbind(dataset[[cnt]][1],apply(dataset[[cnt]][-1],2,FUN.1))
#Convert dataframe to xts
for(iii in 1:cnt){
if(class(dataset[[iii]])=="data.frame"){
dataset[[iii]]<-as.xts(dataset[[iii]][,-1],order.by=as.Date(dataset[[iii]][,1]))
}
}
#individual data and merge
no<-0 #index no for data
all.data<-list()
data<-list()
for(iii in 1:cnt){
for(ddd in 1:ncol(dataset[[iii]])){
no<-no+1
data[[no]]<-na.omit(dataset[[iii]][,ddd])
if(no==1){all.data[[1]]<-data[[no]]}else{all.data[[1]]<-merge.xts(all.data[[1]],data[[no]],all=T)}
}
}
#Nikkei in USD
all.data[[1]]$Nikkei.in.USD<-all.data[[1]]$Nikkei.Close*all.data[[1]]$JPY.USD
no<-no+1
data[[no]]<-na.omit(all.data[[1]]$Nikkei.in.USD)
#USD/JPY
all.data[[1]]$USD.JPY<-1/all.data[[1]]$JPY.USD
no<-no+1
data[[no]]<-na.omit(all.data[[1]]$USD.JPY)
#1st difference as xts
for(ddd in 1:no){
if(ddd==1){all.data[[2]]<-diff(na.omit(all.data[[1]][,ddd]))[-1]}else{all.data[[2]]<-merge.xts(all.data[[2]],diff(na.omit(all.data[[1]][,ddd]))[-1],all=T)}
}
#Logarithmic Return as xts.caution value under zero
for(ddd in 1:no){
if(ddd==1){all.data[[3]]<-round(diff(log(na.omit(all.data[[1]][,ddd])))[-1]*100,2)}else{all.data[[3]]<-merge.xts(all.data[[3]],round(diff(log(na.omit(all.data[[1]][,ddd])))[-1]*100,2),all=T)}
}
#return
for(ddd in 1:no){
tmp<-na.omit(all.data[[1]][,ddd])
tmp<-round(diff(tmp,lag=1)/lag(tmp,1)*100,2)[-1]
if(ddd==1){all.data[[4]]<-tmp}else{all.data[[4]]<-merge.xts(all.data[[4]],tmp,all=T)}
}
#all.data[[1]]:level
#all.data[[2]]:1stdifference
#all.data[[3]]:logarithmicreturn
#all.data[[4]]:return
for(ddd in 1:no){
#cat(ddd,"-",colnames(data[[ddd]]),"\n")  
}
data.m<-list()
data.m.df<-list()
#obj<-c(1,2,4,7,8,9,10,11,51)#stock index
#obj<-c(53,55,68,74,75)#Japan
obj<-c(13,20:23)#commodity price
#obj<-c(29:32,26,41)#brics and bitcoin
#obj<-c(24:28)#commodity currency
for(iii in 1:length(all.data)){
data.m[[iii]]<-all.data[[iii]][,obj]
data.m.df[[iii]]<-data.frame(date=index(data.m[[iii]]),data.m[[iii]],row.names=NULL)
}

Plot Entire Period

options(width=850)
n.col<-3
diff.date<-365*1000
first.date<-Sys.Date()-diff.date
last.date<-Sys.Date()-0
buf<-data.m[[1]][paste(first.date,"::",last.date,sep="")]
par(mfrow=c(ceiling(length(obj)/n.col),n.col),mar=c(3,4,3,3))
plotType="l"
for(ddd in 1:length(obj)){
date.s<-first(index(na.omit(buf[,ddd])))
date.e<-last(index(na.omit(buf[,ddd])))
plot(na.omit(buf[,ddd]),main=paste(colnames(buf)[ddd],"\n",date.s,"-",date.e),xlab="",ylab="value",type=plotType)
}

Level,1st Difference,Logarithmic Return and Return in the last 7days

options(width=850)
for(iii in 1:length(all.data)){
switch(iii,
cat("Level\n"),
cat("1st Difference\n"),
cat("Logarithmic Return\n"),
cat("Return\n")
)
print(tail(data.m[[iii]],7))
cat("\n\n")
}
## Level
##            DCOILWTICO XAU.USD XAG.USD XPT.USD XPD.USD
## 2014-10-21         NA 1241.39 17.3854 1268.02 761.462
## 2014-10-22         NA 1249.44 17.4904 1268.02 761.462
## 2014-10-23         NA 1246.80 17.3806 1268.02 761.462
## 2014-10-24         NA 1237.74 17.1963 1268.02 761.462
## 2014-10-25         NA 1231.70 17.2410 1268.02 761.462
## 2014-10-26         NA 1231.52 17.2188 1268.02 761.462
## 2014-10-27         NA 1231.52 17.2188 1251.23 780.485
## 
## 
## 1st Difference
##            DCOILWTICO XAU.USD XAG.USD XPT.USD XPD.USD
## 2014-10-21         NA    2.34  0.0906    8.07   1.462
## 2014-10-22         NA    8.05  0.1050    0.00   0.000
## 2014-10-23         NA   -2.64 -0.1098    0.00   0.000
## 2014-10-24         NA   -9.06 -0.1843    0.00   0.000
## 2014-10-25         NA   -6.04  0.0447    0.00   0.000
## 2014-10-26         NA   -0.18 -0.0222    0.00   0.000
## 2014-10-27         NA    0.00  0.0000  -16.79  19.023
## 
## 
## Logarithmic Return
##            DCOILWTICO XAU.USD XAG.USD XPT.USD XPD.USD
## 2014-10-21         NA    0.19    0.52    0.64    0.19
## 2014-10-22         NA    0.65    0.60    0.00    0.00
## 2014-10-23         NA   -0.21   -0.63    0.00    0.00
## 2014-10-24         NA   -0.73   -1.07    0.00    0.00
## 2014-10-25         NA   -0.49    0.26    0.00    0.00
## 2014-10-26         NA   -0.01   -0.13    0.00    0.00
## 2014-10-27         NA    0.00    0.00   -1.33    2.47
## 
## 
## Return
##            DCOILWTICO XAU.USD XAG.USD XPT.USD XPD.USD
## 2014-10-21         NA    0.19    0.52    0.64    0.19
## 2014-10-22         NA    0.65    0.60    0.00    0.00
## 2014-10-23         NA   -0.21   -0.63    0.00    0.00
## 2014-10-24         NA   -0.73   -1.06    0.00    0.00
## 2014-10-25         NA   -0.49    0.26    0.00    0.00
## 2014-10-26         NA   -0.01   -0.13    0.00    0.00
## 2014-10-27         NA    0.00    0.00   -1.32    2.50

Unit Root Test(function adf.test()).Level and 1stDifference

options(width=850)
diff.date<-365*1000
first.date<-Sys.Date()-diff.date
last.date<-Sys.Date()-0
for(iii in 1:2){#length(data.m)){
for(ccc in 1:ncol(data.m[[iii]])){
if(iii==1){
cat("Level ")  
}else if(iii==2){
cat("1stDifference ")  
}else if(iii==3){
cat("LogarithmicReturn ")  
}else if(iii==4){
cat("Return ")  
}
buf<-na.omit(data.m[[iii]][,ccc][paste(first.date,"::",last.date,sep="")])
cat(colnames(buf)[1]," ") 
cat(paste("from",first(index(buf)),"to",last(index(buf)),"\n"))
tmp<-adf.test(buf)
cat(paste("p=",tmp$p.value,",lag order=",tmp$parameter,",method=",tmp$method))
cat("\n\n")
}
}
## Level DCOILWTICO  from 1986-01-02 to 2014-10-20 
## p= 0.115449931077658 ,lag order= 19 ,method= Augmented Dickey-Fuller Test
## 
## Level XAU.USD  from 2013-06-15 to 2014-10-27 
## p= 0.209229943240458 ,lag order= 7 ,method= Augmented Dickey-Fuller Test
## 
## Level XAG.USD  from 2013-06-15 to 2014-10-27 
## p= 0.33259335090509 ,lag order= 7 ,method= Augmented Dickey-Fuller Test
## 
## Level XPT.USD  from 2013-06-15 to 2014-10-27 
## p= 0.768471421906037 ,lag order= 7 ,method= Augmented Dickey-Fuller Test
## 
## Level XPD.USD  from 2013-06-15 to 2014-10-27 
## p= 0.658214087943696 ,lag order= 7 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference DCOILWTICO  from 1986-01-03 to 2014-10-20 
## p= 0.01 ,lag order= 19 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference XAU.USD  from 2013-06-16 to 2014-10-27 
## p= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference XAG.USD  from 2013-06-16 to 2014-10-27 
## p= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference XPT.USD  from 2013-06-16 to 2014-10-27 
## p= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference XPD.USD  from 2013-06-16 to 2014-10-27 
## p= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test

Plot with smoothed line.Period 1year

plots<-list()
n.col<-3
diff.date<-365*1
first.date<-Sys.Date()-diff.date
for(iii in 2:ncol(data.m.df[[1]])){
tmp<-data.m.df[[1]][,c(1,iii)]
tmp<-subset(tmp,first.date<=tmp[,1]) 
tmp<-na.omit(tmp)
colnames(tmp)[2]<-"value"
date.s<-first(tmp[,1])
date.e<-last(tmp[,1])
g<-ggplot(tmp,aes(x=date,y=value))
g<-g+geom_line()
g<-g+scale_x_date(labels=date_format("%Y/%b/%d"))
g<-g+ggtitle(paste(colnames(data.m.df[[1]])[iii],"\n",date.s,"-",date.e))
g<-g+geom_smooth(method=lm)
g<-g+geom_smooth(method=loess,color="red")
g<-g+geom_point()
plots[[iii-1]]<-g
}
multiplot(plotlist=plots,cols=n.col)

Forecast and Test by ARIMA

options(width=850)
resid.list<-list()
n.col<-3
fore.day<-14
diff.date<-365*10
first.date<-Sys.Date()-diff.date
confidenceInterval<-70
for(fff in 1:2){
ggg<-0
par(mfrow=c(ceiling(length(obj)/n.col),n.col),mar=c(3,4,4,4))
if(fff==1){
cat("-- Forecast -- \n")
}else{
cat("-- Tset -- \n")
}
for(iii in 1:ncol(data.m[[1]])){#only level
ggg<-ggg+1
tmp<-na.omit(data.m[[1]][,iii])
if(fff==1){
last.date<-Sys.Date()
}else{
last.date<-index(tmp[nrow(tmp)-fore.day])
}
tmp.0<-tmp[paste(first.date,"::",last.date,sep="")]
tmp.1<-auto.arima(tmp.0,ic="aic",trace=F,stepwise=T) #tmp.1 result of arima
tmp.2<-as.xts(tmp.1$res) #tmp.2 to check for normarity of residual
index(tmp.2)<-index(tmp.0)
colnames(tmp.2)[1]<-paste("Residual",colnames(tmp.0))
tmp.3<-forecast(tmp.1,level=c(confidenceInterval),h=fore.day) #tmp.3 result of forecast
Original<-tmp.3$x
ARIMA.fitted<-tmp.3$fitted
ARIMA.Residual<-tmp.3$resid
tmp.4<-cbind(Original,ARIMA.fitted,ARIMA.Residual)
tmp.4<-as.data.frame(tmp.4) # tmp.4 dataframe
rownames(tmp.4)<-index(tmp.2)
tmp.5<-as.xts(tmp.4) # tmp.5 xts
tmp.5<-tmp.5[paste(first.date,"::",last.date,sep="")]
#text
cat(paste(colnames(data.m[[1]])[iii],"\n"))
cat(paste("from",first(index(tmp.5)),"to",last(index(tmp.5)),"\n"))
print(tmp.1$model$phi)
print(tmp.1$model$theta)
print(tmp.1$model$Delta)
tmp.6<-cbind(tmp.3$lower,tmp.3$mean,tmp.3$upper)
colnames(tmp.6)<-c(paste("Lower",confidenceInterval,"persent",sep=""),"Mean",paste("Upper",confidenceInterval,"persent",sep=""))
tmp.6<-as.data.frame(tmp.6)
if(fff==1){
cat("\nForecast","\n")
print(tmp.6)
chart.TimeSeries(tmp.5[,3],main=paste(colnames(data.m[[1]])[iii],"\n",first(index(tmp.5)),"-",last(index(tmp.5))),type="h",lwd="1",xaxis=F,yaxis.right=T,legend.loc="topright",color="red")
par(new=T)
chart.TimeSeries(tmp.5[,1],main="",yaxis.right=F,lty=3,lwd="1",legend.loc="bottomright",color="black",ylim=(c(min(tmp.5[,1]),max(tmp.5[,1]))))
par(new=T)
chart.TimeSeries(tmp.5[,2],main="",type="l",lwd="1",xaxis=F,yaxis.right=F,legend.loc="topleft",color="blue",yaxis=F)
}
else{
cat("\nForecast and Its Result","\n")
tmp.7<-tmp[paste((last.date+1),"::",sep="")]
tmp.7<-data.frame(date=index(tmp.7),tmp.7,row.names=NULL)
tmp.8<-cbind(tmp.6,tmp.7)
print(tmp.8)
fore.max<-max(tmp.8[,3],tmp.8[,5])
fore.min<-min(tmp.8[,1],tmp.8[,5])
plot(x=tmp.8$date,y=tmp.8[,5],ylim=c(fore.min,fore.max),type="l",lwd="2",xlab="Date",ylab=colnames(tmp.8)[5])
par(new=T)
plot(x=tmp.8$date,y=tmp.8[,1],ylim=c(fore.min,fore.max),type="l",lwd="2",col=2,xlab="",ylab="")
par(new=T)
plot(x=tmp.8$date,y=tmp.8[,2],ylim=c(fore.min,fore.max),type="l",lwd="2",col=4,xlab="",ylab="")
par(new=T)
plot(x=tmp.8$date,y=tmp.8[,3],ylim=c(fore.min,fore.max),type="l",lwd="2",col=2,xlab="",ylab="",main=colnames(data.m[[1]])[iii])
}
cat(paste("Unit Root Test of Level p.value=",adf.test(tmp.0)$p.value,",lag order=",adf.test(tmp.0)$parameter,",method=",adf.test(tmp.0)$method,"\n"))
cat(paste("Unit Root Test of 1st Difference p.value=",adf.test(diff(tmp.0)[-1])$p.value,",lag order=",adf.test(diff(tmp.0)[-1])$parameter,",method=",adf.test(diff(tmp.0)[-1])$method,"\n"))
cat("Normality test for residual p.value=",paste(shapiro.test(tmp.1$res)$p.value,"method=",shapiro.test(tmp.1$res)$method))
resid.list[[ggg]]<-tmp.1$res
cat("\n\n")
}
par(mfrow=c(ceiling(length(obj)/n.col),n.col),mar=c(3,4,4,4))
for(zzz in 1:ggg){
if(fff==1){qqnorm(resid.list[[zzz]],main=paste("Forecast","\n",colnames(data.m[[1]])[zzz]));qqline(resid.list[[zzz]],col=2)}else{qqnorm(resid.list[[zzz]],main=paste("Forecast and Result","\n",colnames(data.m[[1]])[zzz]));qqline(resid.list[[zzz]],col=2)} 
}
}

## -- Forecast -- 
## DCOILWTICO 
## from 2004-10-29 to 2014-10-20 
## [1] -0.8641092 -0.6649384
## [1]  0.825767443  0.601284134 -0.009923408  0.039742590
## [1] 1
## 
## Forecast 
##    Lower70persent     Mean Upper70persent
## 1        81.12112 82.91623       84.71134
## 2        80.36627 82.85675       85.34722
## 3        79.83010 82.82949       85.82888
## 4        79.42414 82.89511       86.36608
## 5        78.95142 82.85653       86.76165
## 6        78.58613 82.84623       87.10634
## 7        78.27552 82.88078       87.48605
## 8        77.92526 82.85778       87.79030
## 9        77.63069 82.85468       88.07868
## 10       77.36370 82.87266       88.38161
## 11       77.07741 82.85918       88.64096
## 12       76.82357 82.85888       88.89418
## 13       76.58486 82.86810       89.15134
## 14       76.33814 82.86033       89.38253
## Unit Root Test of Level p.value= 0.318593957368946 ,lag order= 13 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 13 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 9.05412375027202e-31 method= Shapiro-Wilk normality test
## 
## XAU.USD 
## from 2013-06-15 to 2014-10-27 
## numeric(0)
## [1] 0.3234325
## [1] 1
## 
## Forecast 
##    Lower70persent     Mean Upper70persent
## 1        1222.621 1231.416       1240.210
## 2        1216.828 1231.416       1246.004
## 3        1212.754 1231.416       1250.078
## 4        1209.422 1231.416       1253.410
## 5        1206.532 1231.416       1256.300
## 6        1203.945 1231.416       1258.887
## 7        1201.581 1231.416       1261.251
## 8        1199.391 1231.416       1263.441
## 9        1197.341 1231.416       1265.490
## 10       1195.408 1231.416       1267.423
## 11       1193.574 1231.416       1269.258
## 12       1191.825 1231.416       1271.007
## 13       1190.149 1231.416       1272.683
## 14       1188.539 1231.416       1274.293
## Unit Root Test of Level p.value= 0.209229943240458 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 1.04590983694182e-15 method= Shapiro-Wilk normality test
## 
## XAG.USD 
## from 2013-06-15 to 2014-10-27 
## numeric(0)
## [1] 0.3376265
## [1] 1
## 
## Forecast 
##    Lower70persent     Mean Upper70persent
## 1        17.00925 17.22485       17.44045
## 2        16.86478 17.22485       17.58492
## 3        16.76353 17.22485       17.68617
## 4        16.68080 17.22485       17.76890
## 5        16.60910 17.22485       17.84061
## 6        16.54491 17.22485       17.90480
## 7        16.48628 17.22485       17.96343
## 8        16.43197 17.22485       18.01773
## 9        16.38115 17.22485       18.06855
## 10       16.33323 17.22485       18.11648
## 11       16.28775 17.22485       18.16196
## 12       16.24438 17.22485       18.20533
## 13       16.20284 17.22485       18.24686
## 14       16.16293 17.22485       18.28677
## Unit Root Test of Level p.value= 0.33259335090509 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 3.37627961244886e-16 method= Shapiro-Wilk normality test
## 
## XPT.USD 
## from 2013-06-15 to 2014-10-27 
## numeric(0)
## numeric(0)
## [1] 1
## 
## Forecast 
##    Lower70persent    Mean Upper70persent
## 1        1238.917 1251.23       1263.543
## 2        1233.817 1251.23       1268.643
## 3        1229.904 1251.23       1272.556
## 4        1226.605 1251.23       1275.855
## 5        1223.698 1251.23       1278.762
## 6        1221.070 1251.23       1281.390
## 7        1218.654 1251.23       1283.806
## 8        1216.404 1251.23       1286.056
## 9        1214.292 1251.23       1288.168
## 10       1212.294 1251.23       1290.166
## 11       1210.393 1251.23       1292.067
## 12       1208.577 1251.23       1293.883
## 13       1206.836 1251.23       1295.624
## 14       1205.160 1251.23       1297.300
## Unit Root Test of Level p.value= 0.768471421906037 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 4.88776268306439e-22 method= Shapiro-Wilk normality test
## 
## XPD.USD 
## from 2013-06-15 to 2014-10-27 
## [1]  1.9022206 -0.9271351
## [1] -1.8984877  0.9213662
## [1] 1
## 
## Forecast 
##    Lower70persent     Mean Upper70persent
## 1        771.3642 780.2950       789.2258
## 2        767.4465 780.1002       792.7538
## 3        764.3917 779.9057       795.4197
## 4        761.7969 779.7163       797.6357
## 5        759.5103 779.5364       799.5626
## 6        757.4560 779.3699       801.2837
## 7        755.5900 779.2197       802.8495
## 8        753.8836 779.0886       804.2937
## 9        752.3165 778.9784       805.6404
## 10       750.8734 778.8903       806.9073
## 11       749.5414 778.8249       808.1084
## 12       748.3099 778.7822       809.2545
## 13       747.1687 778.7616       810.3544
## 14       746.1089 778.7619       811.4149
## Unit Root Test of Level p.value= 0.658214087943696 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 3.38607087697302e-22 method= Shapiro-Wilk normality test
## 
## -- Tset -- 
## DCOILWTICO 
## from 2004-10-29 to 2014-09-30 
## [1] -0.873223 -0.675519
## [1]  0.83408304  0.61032358 -0.01216508  0.03806827
## [1] 1
## 
## Forecast and Its Result 
##    Lower70persent     Mean Upper70persent       date DCOILWTICO
## 1        89.48905 91.28610       93.08316 2014-10-01      90.74
## 2        89.00898 91.50116       93.99334 2014-10-02      91.02
## 3        88.23243 91.23295       94.23347 2014-10-03      89.76
## 4        87.72296 91.19416       94.66536 2014-10-06      90.33
## 5        87.50528 91.40921       95.31314 2014-10-07      88.89
## 6        86.98949 91.24763       95.50576 2014-10-08      87.29
## 7        86.64060 91.24346       95.84632 2014-10-09      85.76
## 8        86.42676 91.35625       96.28574 2014-10-10      85.87
## 9        86.04034 91.26057       96.48080 2014-10-13      85.73
## 10       85.76304 91.26793       96.77281 2014-10-14      81.72
## 11       85.54885 91.32614       97.10343 2014-10-15      81.82
## 12       85.24012 91.27034       97.30055 2014-10-16      82.33
## 13       85.00184 91.27974       97.55764 2014-10-17      82.80
## 14       84.79271 91.30922       97.82574 2014-10-20      82.76
## Unit Root Test of Level p.value= 0.281349684819878 ,lag order= 13 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 13 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 1.10344236822892e-30 method= Shapiro-Wilk normality test
## 
## XAU.USD 
## from 2013-06-15 to 2014-10-13 
## numeric(0)
## [1] 0.3233919
## [1] 1
## 
## Forecast and Its Result 
##    Lower70persent     Mean Upper70persent       date XAU.USD
## 1        1214.311 1223.192       1232.073 2014-10-14 1230.68
## 2        1208.461 1223.192       1237.924 2014-10-15 1234.41
## 3        1204.347 1223.192       1242.038 2014-10-16 1232.25
## 4        1200.982 1223.192       1245.402 2014-10-17 1240.83
## 5        1198.064 1223.192       1248.321 2014-10-18 1240.83
## 6        1195.451 1223.192       1250.933 2014-10-19 1239.05
## 7        1193.064 1223.192       1253.321 2014-10-20 1239.05
## 8        1190.852 1223.192       1255.532 2014-10-21 1241.39
## 9        1188.783 1223.192       1257.601 2014-10-22 1249.44
## 10       1186.831 1223.192       1259.553 2014-10-23 1246.80
## 11       1184.979 1223.192       1261.406 2014-10-24 1237.74
## 12       1183.212 1223.192       1263.172 2014-10-25 1231.70
## 13       1181.520 1223.192       1264.864 2014-10-26 1231.52
## 14       1179.894 1223.192       1266.490 2014-10-27 1231.52
## Unit Root Test of Level p.value= 0.244947431869148 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 2.13281666305672e-15 method= Shapiro-Wilk normality test
## 
## XAG.USD 
## from 2013-06-15 to 2014-10-13 
## numeric(0)
## [1] 0.3393452
## [1] 1
## 
## Forecast and Its Result 
##    Lower70persent     Mean Upper70persent       date XAG.USD
## 1        17.17236 17.39037       17.60838 2014-10-14 17.4665
## 2        17.02597 17.39037       17.75476 2014-10-15 17.4809
## 3        16.92342 17.39037       17.85732 2014-10-16 17.3332
## 4        16.83964 17.39037       17.94109 2014-10-17 17.4488
## 5        16.76703 17.39037       18.01371 2014-10-18 17.3764
## 6        16.70203 17.39037       18.07871 2014-10-19 17.2948
## 7        16.64266 17.39037       18.13808 2014-10-20 17.2948
## 8        16.58767 17.39037       18.19307 2014-10-21 17.3854
## 9        16.53621 17.39037       18.24452 2014-10-22 17.4904
## 10       16.48768 17.39037       18.29305 2014-10-23 17.3806
## 11       16.44163 17.39037       18.33910 2014-10-24 17.1963
## 12       16.39772 17.39037       18.38302 2014-10-25 17.2410
## 13       16.35566 17.39037       18.42507 2014-10-26 17.2188
## 14       16.31525 17.39037       18.46548 2014-10-27 17.2188
## Unit Root Test of Level p.value= 0.331316188025169 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 8.38849770094056e-16 method= Shapiro-Wilk normality test
## 
## XPT.USD 
## from 2013-06-15 to 2014-10-13 
## [1] 0.9828796
## numeric(0)
## numeric(0)
## 
## Forecast and Its Result 
##    Lower70persent     Mean Upper70persent       date XPT.USD
## 1        1263.051 1275.451       1287.851 2014-10-14 1273.00
## 2        1260.473 1277.859       1295.246 2014-10-15 1273.00
## 3        1259.113 1280.227       1301.341 2014-10-16 1273.00
## 4        1258.379 1282.554       1306.729 2014-10-17 1273.00
## 5        1258.039 1284.841       1311.643 2014-10-18 1273.00
## 6        1257.973 1287.089       1316.205 2014-10-19 1273.00
## 7        1258.110 1289.298       1320.487 2014-10-20 1259.95
## 8        1258.403 1291.470       1324.537 2014-10-21 1268.02
## 9        1258.818 1293.605       1328.391 2014-10-22 1268.02
## 10       1259.333 1295.703       1332.072 2014-10-23 1268.02
## 11       1259.928 1297.765       1335.601 2014-10-24 1268.02
## 12       1260.590 1299.791       1338.993 2014-10-25 1268.02
## 13       1261.307 1301.783       1342.260 2014-10-26 1268.02
## 14       1262.070 1303.741       1345.413 2014-10-27 1251.23
## Unit Root Test of Level p.value= 0.648689416502064 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 7.13989494965271e-21 method= Shapiro-Wilk normality test
## 
## XPD.USD 
## from 2013-06-15 to 2014-10-13 
## [1]  1.9051661 -0.9314714
## [1] -1.8935173  0.9181591
## [1] 1
## 
## Forecast and Its Result 
##    Lower70persent     Mean Upper70persent       date XPD.USD
## 1        785.1021 793.9799       802.8577 2014-10-14 793.000
## 2        782.2063 794.8347       807.4631 2014-10-15 793.000
## 3        780.0082 795.5505       811.0927 2014-10-16 793.000
## 4        778.1006 796.1180       814.1353 2014-10-17 793.000
## 5        776.3279 796.5324       816.7369 2014-10-18 793.000
## 6        774.6140 796.7933       818.9725 2014-10-19 793.000
## 7        772.9188 796.9043       820.8899 2014-10-20 760.000
## 8        771.2210 796.8729       822.5248 2014-10-21 761.462
## 9        769.5115 796.7096       823.9077 2014-10-22 761.462
## 10       767.7889 796.4277       825.0666 2014-10-23 761.462
## 11       766.0569 796.0428       826.0287 2014-10-24 761.462
## 12       764.3230 795.5721       826.8211 2014-10-25 761.462
## 13       762.5972 795.0338       827.4703 2014-10-26 761.462
## 14       760.8907 794.4467       828.0026 2014-10-27 780.485
## Unit Root Test of Level p.value= 0.495934430559584 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 7 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 2.19849046214247e-21 method= Shapiro-Wilk normality test

Autocorrelation

options(width=850)
n.col<-3
data.type<-1 #1 level 2 1stdiff 3 log 4 return
par(mfrow=c(ceiling(length(obj)/n.col),n.col),mar=c(3,4,4,4))
diff.date<-365*1000
first.date<-Sys.Date()-diff.date
for(iii in 1:length(obj)){
tmp.0<-na.omit(data.m[[data.type]][,iii])
tmp.0<-tmp.0[paste(first.date,"::",Sys.Date(),sep="")]
acf.result<-acf(tmp.0,lag=90,main=paste(colnames(data.m[[data.type]][,iii]),first(index(tmp.0)),"-",last(index(tmp.0))))
tmp.1<-acf.result$lag
tmp.2<-acf.result$acf
if(iii==1){result.df<-cbind(tmp.1,round(tmp.2,3))}else{result.df<-cbind(result.df,round(tmp.2,3))}
colnames(result.df)[iii+1]<-colnames(data.m[[data.type]])[iii]
}
#colnames(result.df)[1]<-"lag"
#gTable<-gvisTable(as.data.frame(result.df))
#print(gTable,tag="chart")

Correlation.1stDifference

options(width = 850)
diff.date<-360*1
first.date<-Sys.Date()-diff.date
last.date<-Sys.Date()-0
sss<-2 #1stdiff
buf<-na.omit(data.m[[sss]])
buf<-buf[paste(first.date,"::",last.date,sep="")]
#Pearson 
result.cor<-round(cor(buf,method="pearson"),3)
result.cor.p<-data.frame(Response=row.names(result.cor),result.cor,row.names=NULL)
#Spearman 
result.cor<-round(cor(buf,method="spearman"),3)
result.cor.s<-data.frame(Response=row.names(result.cor),result.cor,row.names=NULL)
options(width = 850)
split<-5
for(ppp in 1:2){
s<-2-split
if(ppp==1){
tmp.0<-result.cor.p
#Pearson 
cat("1st Difference","\n")
cat("Pearson","\n")
cat(paste("From",first(index(buf)),"-",last(index(buf)),"\n"))
}else{
tmp.0<-result.cor.s
#Spearman 
cat("1st Difference","\n")
cat("Spearman","\n")
cat(paste("From",first(index(buf)),"-",last(index(buf)),"\n"))
}
table.col<-ncol(tmp.0)-1
for(lll in 1:ceiling(table.col/split)){
s<-s+split
if(lll!=ceiling(table.col/split)){e<-s+(split-1)}else{e<-table.col+1}
tmp.1<-tmp.0[,c(1,s:e)]
gTable<-gvisTable(tmp.1)
print(gTable,tag="chart")
}
}

1st Difference Pearson From 2013-11-01 - 2014-10-20

1st Difference Spearman From 2013-11-01 - 2014-10-20

Table of Return

Index<-colnames(data.m[[4]])
for(iii in 1:ncol(data.m[[4]])){
tmp<-as.vector(last(na.omit(data.m[[4]][,iii])))
if(iii==1){Return<-tmp}else{Return<-c(Return,tmp)}
tmp<-index(last(na.omit(data.m[[4]][,iii])))
if(iii==1){Date<-tmp}else{Date<-c(Date,tmp)}
}
return.table<-data.frame(Index,Return,Date,row.names=NULL)
colnames(return.table)[2]<-"Return.%"
gTable<-gvisTable(return.table)
print(gTable,tag="chart")

Data Source/Reference