Sys.time()

[1] “2014-10-24 13:19:59 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,Daily price index 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
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,3,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
##            N225.Close HSI.Close GSPC.Close FTSE.Close STI.Close KS11.Close TWII.Close GDAXI.Close BVSP.Close
## 2014-10-18         NA        NA         NA         NA        NA         NA         NA          NA         NA
## 2014-10-19         NA        NA         NA         NA        NA         NA         NA          NA         NA
## 2014-10-20   15111.23  23070.26    1904.01     6267.1   3181.05    1930.06    8663.14     8717.76      54303
## 2014-10-21   14804.28  23088.58    1941.28     6372.3   3202.74    1915.28    8654.64     8886.96      52432
## 2014-10-22   15195.77  23403.97    1927.11     6399.7        NA    1936.97    8748.83     8940.14      52411
## 2014-10-23   15138.96  23333.18    1950.82     6419.2   3236.50    1931.65    8731.07     9047.31      50713
## 2014-10-24         NA        NA         NA         NA        NA         NA         NA          NA         NA
## 
## 
## 1st Difference
##            N225.Close HSI.Close GSPC.Close FTSE.Close STI.Close KS11.Close TWII.Close GDAXI.Close BVSP.Close
## 2014-10-18         NA        NA         NA         NA        NA         NA         NA          NA         NA
## 2014-10-19         NA        NA         NA         NA        NA         NA         NA          NA         NA
## 2014-10-20     578.72     47.05      17.25      -43.2     13.32      29.40     150.26     -132.51      -1421
## 2014-10-21    -306.95     18.32      37.27      105.2     21.69     -14.78      -8.50      169.20      -1871
## 2014-10-22     391.49    315.39     -14.17       27.4        NA      21.69      94.19       53.18        -21
## 2014-10-23     -56.81    -70.79      23.71       19.5     33.76      -5.32     -17.76      107.17      -1698
## 2014-10-24         NA        NA         NA         NA        NA         NA         NA          NA         NA
## 
## 
## Logarithmic Return
##            N225.Close HSI.Close GSPC.Close FTSE.Close STI.Close KS11.Close TWII.Close GDAXI.Close BVSP.Close
## 2014-10-18         NA        NA         NA         NA        NA         NA         NA          NA         NA
## 2014-10-19         NA        NA         NA         NA        NA         NA         NA          NA         NA
## 2014-10-20       3.90      0.20       0.91      -0.69      0.42       1.53       1.75       -1.51      -2.58
## 2014-10-21      -2.05      0.08       1.94       1.66      0.68      -0.77      -0.10        1.92      -3.51
## 2014-10-22       2.61      1.36      -0.73       0.43        NA       1.13       1.08        0.60      -0.04
## 2014-10-23      -0.37     -0.30       1.22       0.30      1.05      -0.28      -0.20        1.19      -3.29
## 2014-10-24         NA        NA         NA         NA        NA         NA         NA          NA         NA
## 
## 
## Return
##            N225.Close HSI.Close GSPC.Close FTSE.Close STI.Close KS11.Close TWII.Close GDAXI.Close BVSP.Close
## 2014-10-18         NA        NA         NA         NA        NA         NA         NA          NA         NA
## 2014-10-19         NA        NA         NA         NA        NA         NA         NA          NA         NA
## 2014-10-20       3.98      0.20       0.91      -0.68      0.42       1.55       1.77       -1.50      -2.55
## 2014-10-21      -2.03      0.08       1.96       1.68      0.68      -0.77      -0.10        1.94      -3.45
## 2014-10-22       2.64      1.37      -0.73       0.43        NA       1.13       1.09        0.60      -0.04
## 2014-10-23      -0.37     -0.30       1.23       0.30      1.05      -0.27      -0.20        1.20      -3.24
## 2014-10-24         NA        NA         NA         NA        NA         NA         NA          NA         NA

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 N225.Close  from 2007-01-04 to 2014-10-23 
## p= 0.770905289050784 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## Level HSI.Close  from 2007-01-02 to 2014-10-23 
## p= 0.432536357718551 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## Level GSPC.Close  from 2007-01-03 to 2014-10-23 
## p= 0.828274846642123 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## Level FTSE.Close  from 2007-01-01 to 2014-10-23 
## p= 0.510869585717671 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## Level STI.Close  from 2007-01-03 to 2014-10-23 
## p= 0.603844695192856 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## Level KS11.Close  from 2007-01-02 to 2014-10-23 
## p= 0.367295202105757 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## Level TWII.Close  from 2007-01-02 to 2014-10-23 
## p= 0.578538423136632 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## Level GDAXI.Close  from 2007-01-02 to 2014-10-23 
## p= 0.648629929226113 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## Level BVSP.Close  from 2007-01-02 to 2014-10-23 
## p= 0.352856661954917 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference N225.Close  from 2007-01-05 to 2014-10-23 
## p= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference HSI.Close  from 2007-01-03 to 2014-10-23 
## p= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference GSPC.Close  from 2007-01-04 to 2014-10-23 
## p= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference FTSE.Close  from 2007-01-02 to 2014-10-23 
## p= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference STI.Close  from 2007-01-04 to 2014-10-23 
## p= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference KS11.Close  from 2007-01-03 to 2014-10-23 
## p= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference TWII.Close  from 2007-01-03 to 2014-10-23 
## p= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference GDAXI.Close  from 2007-01-03 to 2014-10-23 
## p= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test
## 
## 1stDifference BVSP.Close  from 2007-01-03 to 2014-10-23 
## p= 0.01 ,lag order= 12 ,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[,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 -- 
## N225.Close 
## from 2007-01-04 to 2014-10-23 
## [1] -0.4518621
## [1] 0.3998546
## [1] 1
## 
## Forecast 
##    Lower70persent     Mean Upper70persent
## 1        14959.46 15154.57       15349.67
## 2        14878.67 15147.51       15416.36
## 3        14821.76 15150.70       15479.64
## 4        14770.65 15149.26       15527.87
## 5        14727.01 15149.91       15572.81
## 6        14686.82 15149.62       15612.42
## 7        14650.16 15149.75       15649.34
## 8        14615.86 15149.69       15683.52
## 9        14583.71 15149.72       15715.72
## 10       14553.26 15149.70       15746.15
## 11       14524.30 15149.71       15775.12
## 12       14496.62 15149.71       15802.80
## 13       14470.07 15149.71       15829.35
## 14       14444.51 15149.71       15854.90
## Unit Root Test of Level p.value= 0.770905289050784 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 7.13133049032009e-25 method= Shapiro-Wilk normality test
## 
## HSI.Close 
## from 2007-01-02 to 2014-10-23 
## numeric(0)
## numeric(0)
## [1] 1
## 
## Forecast 
##    Lower70persent     Mean Upper70persent
## 1        22979.78 23333.18       23686.58
## 2        22833.40 23333.18       23832.96
## 3        22721.07 23333.18       23945.29
## 4        22626.38 23333.18       24039.98
## 5        22542.96 23333.18       24123.40
## 6        22467.53 23333.18       24198.83
## 7        22398.17 23333.18       24268.19
## 8        22333.62 23333.18       24332.74
## 9        22272.98 23333.18       24393.38
## 10       22215.63 23333.18       24450.73
## 11       22161.09 23333.18       24505.27
## 12       22108.97 23333.18       24557.39
## 13       22058.98 23333.18       24607.38
## 14       22010.88 23333.18       24655.48
## Unit Root Test of Level p.value= 0.432536357718551 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 5.87164625894914e-26 method= Shapiro-Wilk normality test
## 
## GSPC.Close 
## from 2007-01-03 to 2014-10-23 
## numeric(0)
## [1] -0.1194303
## [1] 1
## 
## Forecast 
##    Lower70persent     Mean Upper70persent
## 1        1931.474 1948.123       1964.772
## 2        1925.939 1948.123       1970.307
## 3        1921.532 1948.123       1974.714
## 4        1917.758 1948.123       1978.488
## 5        1914.404 1948.123       1981.842
## 6        1911.355 1948.123       1984.891
## 7        1908.540 1948.123       1987.706
## 8        1905.912 1948.123       1990.334
## 9        1903.438 1948.123       1992.807
## 10       1901.095 1948.123       1995.151
## 11       1898.862 1948.123       1997.383
## 12       1896.727 1948.123       1999.519
## 13       1894.677 1948.123       2001.569
## 14       1892.702 1948.123       2003.543
## Unit Root Test of Level p.value= 0.828274846642123 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 1.77102277666913e-26 method= Shapiro-Wilk normality test
## 
## FTSE.Close 
## from 2007-01-01 to 2014-10-23 
## [1] 0.5910589
## [1] -0.6487705
## [1] 1
## 
## Forecast 
##    Lower70persent     Mean Upper70persent
## 1        6344.996 6414.938       6484.880
## 2        6316.318 6412.419       6508.521
## 3        6295.733 6410.930       6526.127
## 4        6279.177 6410.050       6540.924
## 5        6265.022 6409.530       6554.039
## 6        6252.451 6409.223       6565.994
## 7        6241.003 6409.041       6577.079
## 8        6230.397 6408.933       6587.470
## 9        6220.451 6408.870       6597.289
## 10       6211.043 6408.832       6606.622
## 11       6202.085 6408.810       6615.536
## 12       6193.512 6408.797       6624.082
## 13       6185.276 6408.789       6632.303
## 14       6177.337 6408.785       6640.233
## Unit Root Test of Level p.value= 0.510869585717671 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 1.49212899812501e-24 method= Shapiro-Wilk normality test
## 
## STI.Close 
## from 2007-01-03 to 2014-10-23 
## numeric(0)
## numeric(0)
## [1] 1
## 
## Forecast 
##    Lower70persent   Mean Upper70persent
## 1        3202.130 3236.5       3270.870
## 2        3187.894 3236.5       3285.106
## 3        3176.970 3236.5       3296.030
## 4        3167.761 3236.5       3305.239
## 5        3159.647 3236.5       3313.353
## 6        3152.312 3236.5       3320.688
## 7        3145.566 3236.5       3327.434
## 8        3139.288 3236.5       3333.712
## 9        3133.391 3236.5       3339.609
## 10       3127.813 3236.5       3345.187
## 11       3122.508 3236.5       3350.492
## 12       3117.440 3236.5       3355.560
## 13       3112.578 3236.5       3360.422
## 14       3107.900 3236.5       3365.100
## Unit Root Test of Level p.value= 0.603844695192856 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 3.55894512532975e-23 method= Shapiro-Wilk normality test
## 
## KS11.Close 
## from 2007-01-02 to 2014-10-23 
## numeric(0)
## numeric(0)
## [1] 1
## 
## Forecast 
##    Lower70persent    Mean Upper70persent
## 1        1907.969 1931.65       1955.331
## 2        1898.160 1931.65       1965.140
## 3        1890.633 1931.65       1972.667
## 4        1884.288 1931.65       1979.012
## 5        1878.697 1931.65       1984.603
## 6        1873.643 1931.65       1989.657
## 7        1868.996 1931.65       1994.304
## 8        1864.670 1931.65       1998.630
## 9        1860.607 1931.65       2002.693
## 10       1856.764 1931.65       2006.536
## 11       1853.108 1931.65       2010.192
## 12       1849.616 1931.65       2013.684
## 13       1846.266 1931.65       2017.034
## 14       1843.043 1931.65       2020.257
## Unit Root Test of Level p.value= 0.367295202105757 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 3.3244670808979e-23 method= Shapiro-Wilk normality test
## 
## TWII.Close 
## from 2007-01-02 to 2014-10-23 
## numeric(0)
## [1] 0.05340047
## [1] 1
## 
## Forecast 
##    Lower70persent    Mean Upper70persent
## 1        8631.119 8729.85       8828.582
## 2        8586.446 8729.85       8873.254
## 3        8552.702 8729.85       8906.999
## 4        8524.428 8729.85       8935.273
## 5        8499.600 8729.85       8960.100
## 6        8477.201 8729.85       8982.500
## 7        8456.631 8729.85       9003.069
## 8        8437.506 8729.85       9022.195
## 9        8419.557 8729.85       9040.144
## 10       8402.591 8729.85       9057.110
## 11       8386.462 8729.85       9073.239
## 12       8371.057 8729.85       9088.644
## 13       8356.287 8729.85       9103.414
## 14       8342.080 8729.85       9117.621
## Unit Root Test of Level p.value= 0.578538423136632 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 4.47087454249936e-21 method= Shapiro-Wilk normality test
## 
## GDAXI.Close 
## from 2007-01-02 to 2014-10-23 
## numeric(0)
## numeric(0)
## [1] 1
## 
## Forecast 
##    Lower70persent    Mean Upper70persent
## 1        8952.929 9047.31       9141.691
## 2        8913.835 9047.31       9180.785
## 3        8883.837 9047.31       9210.783
## 4        8858.547 9047.31       9236.073
## 5        8836.267 9047.31       9258.353
## 6        8816.124 9047.31       9278.496
## 7        8797.600 9047.31       9297.020
## 8        8780.359 9047.31       9314.261
## 9        8764.166 9047.31       9330.454
## 10       8748.850 9047.31       9345.770
## 11       8734.283 9047.31       9360.337
## 12       8720.364 9047.31       9374.256
## 13       8707.013 9047.31       9387.607
## 14       8694.167 9047.31       9400.453
## Unit Root Test of Level p.value= 0.648629929226113 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 4.44320402584676e-20 method= Shapiro-Wilk normality test
## 
## BVSP.Close 
## from 2007-01-02 to 2014-10-23 
## [1] 0.6707425
## [1] -0.7084959
## [1] 1
## 
## Forecast 
##    Lower70persent     Mean Upper70persent
## 1        49838.57 50835.53       51832.50
## 2        49534.16 50917.72       52301.28
## 3        49303.49 50972.85       52642.21
## 4        49105.12 51009.82       52914.53
## 5        48925.51 51034.63       53143.74
## 6        48758.87 51051.26       53343.66
## 7        48602.21 51062.42       53522.63
## 8        48453.78 51069.90       53686.02
## 9        48312.42 51074.92       53837.43
## 10       48177.24 51078.29       53979.34
## 11       48047.59 51080.55       54113.51
## 12       47922.88 51082.06       54241.25
## 13       47802.66 51083.08       54363.50
## 14       47686.50 51083.76       54481.02
## Unit Root Test of Level p.value= 0.352856661954917 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 2.35500482108225e-17 method= Shapiro-Wilk normality test
## 
## -- Tset -- 
## N225.Close 
## from 2007-01-04 to 2014-10-03 
## [1]  0.39039650  0.03804147 -0.04477962
## [1] -1.4360231  0.4375328
## [1]  2 -1
## 
## Forecast and Its Result 
##    Lower70persent     Mean Upper70persent       date N225.Close
## 1        15518.04 15712.40       15906.77 2014-10-06   15890.95
## 2        15470.17 15738.85       16007.53 2014-10-07   15783.83
## 3        15422.71 15751.62       16080.53 2014-10-08   15595.98
## 4        15385.62 15761.83       16138.04 2014-10-09   15478.93
## 5        15352.15 15769.51       16186.87 2014-10-10   15300.55
## 6        15322.27 15776.71       16231.15 2014-10-13   15300.55
## 7        15294.97 15783.75       16272.52 2014-10-14   14936.51
## 8        15269.81 15790.81       16311.81 2014-10-15   15073.52
## 9        15246.39 15797.90       16349.41 2014-10-16   14738.38
## 10       15224.44 15805.02       16385.59 2014-10-17   14532.51
## 11       15203.74 15812.14       16420.53 2014-10-20   15111.23
## 12       15184.12 15819.26       16454.39 2014-10-21   14804.28
## 13       15165.45 15826.38       16487.31 2014-10-22   15195.77
## 14       15147.62 15833.50       16519.38 2014-10-23   15138.96
## Unit Root Test of Level p.value= 0.835736290081778 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 5.19864889355763e-25 method= Shapiro-Wilk normality test
## 
## HSI.Close 
## from 2007-01-02 to 2014-10-03 
## numeric(0)
## numeric(0)
## [1] 1
## 
## Forecast and Its Result 
##    Lower70persent     Mean Upper70persent       date HSI.Close
## 1        22710.34 23064.56       23418.78 2014-10-06  23315.04
## 2        22563.62 23064.56       23565.50 2014-10-07  23422.52
## 3        22451.03 23064.56       23678.09 2014-10-08  23263.33
## 4        22356.12 23064.56       23773.00 2014-10-09  23534.53
## 5        22272.50 23064.56       23856.62 2014-10-10  23088.54
## 6        22196.90 23064.56       23932.22 2014-10-13  23143.38
## 7        22127.38 23064.56       24001.74 2014-10-14  23047.97
## 8        22062.67 23064.56       24066.45 2014-10-15  23140.05
## 9        22001.90 23064.56       24127.22 2014-10-16  22900.94
## 10       21944.42 23064.56       24184.70 2014-10-17  23023.21
## 11       21889.74 23064.56       24239.38 2014-10-20  23070.26
## 12       21837.50 23064.56       24291.62 2014-10-21  23088.58
## 13       21787.40 23064.56       24341.72 2014-10-22  23403.97
## 14       21739.19 23064.56       24389.93 2014-10-23  23333.18
## Unit Root Test of Level p.value= 0.433412629758891 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 7.79448795060175e-26 method= Shapiro-Wilk normality test
## 
## GSPC.Close 
## from 2007-01-03 to 2014-10-03 
## [1] -0.118291732 -0.049706322  0.008687458
## [1] -0.9977429  0.0000000
## [1]  2 -1
## 
## Forecast and Its Result 
##    Lower70persent     Mean Upper70persent       date GSPC.Close
## 1        1949.468 1966.030       1982.593 2014-10-06    1964.82
## 2        1943.994 1966.100       1988.205 2014-10-07    1935.10
## 3        1941.092 1967.302       1993.511 2014-10-08    1968.89
## 4        1938.151 1968.068       1997.985 2014-10-09    1928.21
## 5        1935.630 1968.847       2002.063 2014-10-10    1906.13
## 6        1933.433 1969.655       2005.877 2014-10-13    1874.74
## 7        1931.445 1970.456       2009.467 2014-10-14    1877.70
## 8        1929.631 1971.256       2012.881 2014-10-15    1862.49
## 9        1927.962 1972.057       2016.151 2014-10-16    1862.76
## 10       1926.415 1972.858       2019.301 2014-10-17    1886.76
## 11       1924.970 1973.658       2022.346 2014-10-20    1904.01
## 12       1923.616 1974.459       2025.302 2014-10-21    1941.28
## 13       1922.340 1975.260       2028.180 2014-10-22    1927.11
## 14       1921.134 1976.061       2030.987 2014-10-23    1950.82
## Unit Root Test of Level p.value= 0.867326247131664 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 3.30026040386358e-26 method= Shapiro-Wilk normality test
## 
## FTSE.Close 
## from 2007-01-01 to 2014-10-03 
## [1] 0.597879
## [1] -0.655272
## [1] 1
## 
## Forecast and Its Result 
##    Lower70persent     Mean Upper70persent       date FTSE.Close
## 1        6459.926 6529.813       6599.700 2014-10-06     6563.7
## 2        6434.917 6530.957       6626.998 2014-10-07     6495.6
## 3        6416.519 6531.641       6646.764 2014-10-08     6482.2
## 4        6401.273 6532.050       6662.827 2014-10-09     6431.9
## 5        6387.911 6532.294       6676.677 2014-10-10     6340.0
## 6        6375.827 6532.441       6689.054 2014-10-13     6366.2
## 7        6364.683 6532.528       6700.373 2014-10-14     6392.7
## 8        6354.271 6532.580       6710.890 2014-10-15     6211.6
## 9        6344.454 6532.612       6720.769 2014-10-16     6195.9
## 10       6335.135 6532.630       6730.125 2014-10-17     6310.3
## 11       6326.242 6532.641       6739.041 2014-10-20     6267.1
## 12       6317.719 6532.648       6747.577 2014-10-21     6372.3
## 13       6309.523 6532.652       6755.781 2014-10-22     6399.7
## 14       6301.619 6532.654       6763.690 2014-10-23     6419.2
## Unit Root Test of Level p.value= 0.527718871330587 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 1.3858762490028e-24 method= Shapiro-Wilk normality test
## 
## STI.Close 
## from 2007-01-03 to 2014-10-01 
## numeric(0)
## numeric(0)
## [1] 1
## 
## Forecast and Its Result 
##    Lower70persent    Mean Upper70persent       date STI.Close
## 1        3229.670 3264.09       3298.510 2014-10-02   3228.71
## 2        3215.413 3264.09       3312.767 2014-10-03   3253.24
## 3        3204.473 3264.09       3323.707 2014-10-07   3243.99
## 4        3195.250 3264.09       3332.930 2014-10-08   3226.71
## 5        3187.124 3264.09       3341.056 2014-10-09   3259.25
## 6        3179.778 3264.09       3348.402 2014-10-10   3223.87
## 7        3173.023 3264.09       3355.157 2014-10-13   3202.15
## 8        3166.735 3264.09       3361.445 2014-10-14   3194.40
## 9        3160.830 3264.09       3367.350 2014-10-15   3198.72
## 10       3155.244 3264.09       3372.936 2014-10-16   3154.21
## 11       3149.932 3264.09       3378.248 2014-10-17   3167.73
## 12       3144.855 3264.09       3383.325 2014-10-20   3181.05
## 13       3139.987 3264.09       3388.193 2014-10-21   3202.74
## 14       3135.302 3264.09       3392.878 2014-10-23   3236.50
## Unit Root Test of Level p.value= 0.610611035113095 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 3.47778953628804e-23 method= Shapiro-Wilk normality test
## 
## KS11.Close 
## from 2007-01-02 to 2014-10-01 
## numeric(0)
## numeric(0)
## [1] 1
## 
## Forecast and Its Result 
##    Lower70persent    Mean Upper70persent       date KS11.Close
## 1        1967.810 1991.54       2015.270 2014-10-02    1976.16
## 2        1957.980 1991.54       2025.100 2014-10-06    1968.39
## 3        1950.438 1991.54       2032.642 2014-10-07    1972.91
## 4        1944.079 1991.54       2039.001 2014-10-08    1965.25
## 5        1938.477 1991.54       2044.603 2014-10-10    1940.92
## 6        1933.413 1991.54       2049.667 2014-10-13    1927.21
## 7        1928.755 1991.54       2054.325 2014-10-14    1929.25
## 8        1924.420 1991.54       2058.660 2014-10-15    1925.91
## 9        1920.349 1991.54       2062.731 2014-10-16    1918.83
## 10       1916.498 1991.54       2066.582 2014-10-17    1900.66
## 11       1912.835 1991.54       2070.245 2014-10-20    1930.06
## 12       1909.335 1991.54       2073.745 2014-10-21    1915.28
## 13       1905.979 1991.54       2077.101 2014-10-22    1936.97
## 14       1902.749 1991.54       2080.331 2014-10-23    1931.65
## Unit Root Test of Level p.value= 0.364615453803334 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 3.55594627124396e-23 method= Shapiro-Wilk normality test
## 
## TWII.Close 
## from 2007-01-02 to 2014-10-02 
## numeric(0)
## [1] 0.05668658
## [1] 1
## 
## Forecast and Its Result 
##    Lower70persent     Mean Upper70persent       date TWII.Close
## 1        8875.627 8974.262       9072.897 2014-10-03    9106.28
## 2        8830.763 8974.262       9117.761 2014-10-06    9095.14
## 3        8796.906 8974.262       9151.618 2014-10-07    9040.81
## 4        8768.548 8974.262       9179.976 2014-10-08    8955.18
## 5        8743.652 8974.262       9204.873 2014-10-09    8966.44
## 6        8721.192 8974.262       9227.332 2014-10-13    8711.39
## 7        8700.570 8974.262       9247.954 2014-10-14    8768.39
## 8        8681.396 8974.262       9267.128 2014-10-15    8655.51
## 9        8663.403 8974.262       9285.122 2014-10-16    8633.69
## 10       8646.395 8974.262       9302.129 2014-10-17    8512.88
## 11       8630.227 8974.262       9318.297 2014-10-20    8663.14
## 12       8614.786 8974.262       9333.738 2014-10-21    8654.64
## 13       8599.981 8974.262       9348.543 2014-10-22    8748.83
## 14       8585.740 8974.262       9362.784 2014-10-23    8731.07
## Unit Root Test of Level p.value= 0.599911490754286 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 4.33281895493954e-21 method= Shapiro-Wilk normality test
## 
## GDAXI.Close 
## from 2007-01-02 to 2014-10-02 
## numeric(0)
## numeric(0)
## [1] 1
## 
## Forecast and Its Result 
##    Lower70persent    Mean Upper70persent       date GDAXI.Close
## 1        9101.734 9195.68       9289.626 2014-10-06     9209.51
## 2        9062.821 9195.68       9328.539 2014-10-07     9086.21
## 3        9032.961 9195.68       9358.399 2014-10-08     8995.33
## 4        9007.789 9195.68       9383.571 2014-10-09     9005.02
## 5        8985.611 9195.68       9405.749 2014-10-10     8788.81
## 6        8965.561 9195.68       9425.799 2014-10-13     8812.43
## 7        8947.123 9195.68       9444.237 2014-10-14     8825.21
## 8        8929.961 9195.68       9461.399 2014-10-15     8571.95
## 9        8913.843 9195.68       9477.517 2014-10-16     8582.90
## 10       8898.598 9195.68       9492.762 2014-10-17     8850.27
## 11       8884.097 9195.68       9507.263 2014-10-20     8717.76
## 12       8870.243 9195.68       9521.117 2014-10-21     8886.96
## 13       8856.954 9195.68       9534.406 2014-10-22     8940.14
## 14       8844.167 9195.68       9547.193 2014-10-23     9047.31
## Unit Root Test of Level p.value= 0.678921468812086 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 4.20135839752956e-20 method= Shapiro-Wilk normality test
## 
## BVSP.Close 
## from 2007-01-02 to 2014-10-03 
## [1] 0.6683932
## [1] -0.7062376
## [1] 1
## 
## Forecast and Its Result 
##    Lower70persent     Mean Upper70persent       date BVSP.Close
## 1        53545.84 54536.60       55527.35 2014-10-06      57116
## 2        53159.44 54534.32       55909.20 2014-10-07      57436
## 3        52873.92 54532.80       56191.67 2014-10-08      57058
## 4        52639.01 54531.78       56424.56 2014-10-09      57268
## 5        52435.14 54531.10       56627.07 2014-10-10      55312
## 6        52252.47 54530.65       56808.83 2014-10-13      57957
## 7        52085.30 54530.35       56975.39 2014-10-14      58015
## 8        51930.06 54530.14       57130.23 2014-10-15      56135
## 9        51784.34 54530.01       57275.68 2014-10-16      54298
## 10       51646.46 54529.92       57413.38 2014-10-17      55724
## 11       51515.19 54529.86       57544.52 2014-10-20      54303
## 12       51389.61 54529.82       57670.02 2014-10-21      52432
## 13       51268.99 54529.79       57790.59 2014-10-22      52411
## 14       51152.76 54529.77       57906.78 2014-10-23      50713
## Unit Root Test of Level p.value= 0.333825226423368 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Unit Root Test of 1st Difference p.value= 0.01 ,lag order= 12 ,method= Augmented Dickey-Fuller Test 
## Normality test for residual p.value= 1.46014742613553e-17 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)

1st Difference Pearson From 2013-10-29 - 2014-10-23

1st Difference Spearman From 2013-10-29 - 2014-10-23

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")