2014年9月30日 主要金融指標

Data Source

Federal Reserve Bank of St. Louis http://research.stlouisfed.org/

OANDA Corporation http://www.oanda.com/

Ministry of Finance Japan http://www.mof.go.jp/english/index.htm

Sys.time()

[1] “2014-09-30 14:07:37 JST”

Package

library(knitr)
library(quantmod)
library(xts)
library(gridExtra)
library(ggplot2)

Read Data

diff.date<-365
first.date<-Sys.Date()-diff.date
gap<-100
cnt<-1
all.data<-list()
ts.data<-list()
list.s<-list()
list.s[[1]]<-c("FRED",1,"DCOILWTICO","DGS10")
list.s[[2]]<-c("yahoo",4,"^GSPC","^FTSE","^N225")
list.s[[3]]<-c("oanda",1,"JPY","EUR","AUD","NZD","ZAR","CAD","GBP","CHF","XAU","XAG","XPT","BTC")
for(lll in 1:length(list.s)){
for(iii in 3:length(list.s[[lll]])){
if(list.s[[lll]][1]=="oanda"){
item<-paste("USD/",list.s[[lll]][iii],sep="") 
}
else{
item<- list.s[[lll]][iii]
} 
ts.data[[cnt]]<-getSymbols(item,src=list.s[[lll]][1],auto.assign=FALSE)
ts.data[[cnt]]<-ts.data[[cnt]][,as.double(list.s[[lll]][2])]
cnt<-cnt+1
}
}
#Japanese Government Bonds
url<-c(
10, 
"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"
)
buf<-cnt
cnt<-cnt+1
for(ddd in 2:length(url)){
ts.data[[cnt]]<-read.table(url[ddd],header=T,sep=",",stringsAsFactor=F)
ts.data[[cnt]][,1]<-as.Date(ts.data[[cnt]][,1])
colnames(ts.data[[cnt]])[1]<-"date"
ts.data[[cnt]]<-as.xts(ts.data[[cnt]][,-1],order.by=as.Date(ts.data[[cnt]]$date),stringsAsFactor=F)
ts.data[[cnt]]<-apply.daily(ts.data[[cnt]],function(x) as.numeric(x)) #to convert character to NA
ts.data[[cnt]]<-ts.data[[cnt]][,as.double(url[1])]
#ts.data[[cnt]]<-apply(ts.data[[cnt]],c(1,2),function(x) as.numeric(x)) #change class to matrix
if(ddd==2){ts.data[[buf]]<-ts.data[[cnt]]}else{ts.data[[buf]]<-rbind.xts(ts.data[[buf]],ts.data[[cnt]])}
cnt<-cnt+1
}
cnt<-buf

logarithmic return

for(iii in 1:length(ts.data)){
ts.data[[iii+gap]]<-diff(log(na.omit(ts.data[[iii]])))[-1]
}

Plot

for(iii in 1:4){
if(iii==1 || iii==3){gap<-0}else if(iii==2 || iii==4){gap<-100}
par(mfrow=c(5,4),mar=c(3,4,3,4))
for(ppp in (1+gap):(cnt+gap)){
buf<-ts.data[[ppp]]
if(iii==3 || iii==4){ 
buf<-buf[paste(first.date,"::",sep="")]
} 
buf<-data.frame(date=as.Date(index(buf)),buf,row.names=NULL)
plot(x=buf[,1],y=buf[,2],type="l",main=colnames(buf)[2],xlab="",ylab=colnames(buf)[2],xaxt="n")
axis.Date(side=1,at=seq(first(buf[,1]),last(buf[,1]),"days"),format="%Y/%m/%d")
}
if(iii==1 || iii==3){title(paste("\n","Level",sep=""),outer=T)}else{title(paste("\n","logarithmic return",sep=""),outer=T)}
}

plot of chunk unnamed-chunk-5plot of chunk unnamed-chunk-5plot of chunk unnamed-chunk-5plot of chunk unnamed-chunk-5

Data check

for(iii in 1:cnt){
print(paste(iii,"-",class(ts.data[[iii]])))
if(iii==1){all.data[[1]]<-ts.data[[iii]]}else{all.data[[1]]<-merge(all.data[[1]],ts.data[[iii]])}
}
## [1] "1 - xts" "1 - zoo"
## [1] "2 - xts" "2 - zoo"
## [1] "3 - xts" "3 - zoo"
## [1] "4 - xts" "4 - zoo"
## [1] "5 - xts" "5 - zoo"
## [1] "6 - xts" "6 - zoo"
## [1] "7 - xts" "7 - zoo"
## [1] "8 - xts" "8 - zoo"
## [1] "9 - xts" "9 - zoo"
## [1] "10 - xts" "10 - zoo"
## [1] "11 - xts" "11 - zoo"
## [1] "12 - xts" "12 - zoo"
## [1] "13 - xts" "13 - zoo"
## [1] "14 - xts" "14 - zoo"
## [1] "15 - xts" "15 - zoo"
## [1] "16 - xts" "16 - zoo"
## [1] "17 - xts" "17 - zoo"
## [1] "18 - xts" "18 - zoo"
head(all.data[[1]],10)
##            DCOILWTICO DGS10 GSPC.Close FTSE.Close N225.Close USD.JPY
## 1962-01-02         NA  4.06         NA         NA         NA      NA
## 1962-01-03         NA  4.03         NA         NA         NA      NA
## 1962-01-04         NA  3.99         NA         NA         NA      NA
## 1962-01-05         NA  4.02         NA         NA         NA      NA
## 1962-01-08         NA  4.03         NA         NA         NA      NA
## 1962-01-09         NA  4.05         NA         NA         NA      NA
## 1962-01-10         NA  4.07         NA         NA         NA      NA
## 1962-01-11         NA  4.08         NA         NA         NA      NA
## 1962-01-12         NA  4.08         NA         NA         NA      NA
## 1962-01-15         NA  4.10         NA         NA         NA      NA
##            USD.EUR USD.AUD USD.NZD USD.ZAR USD.CAD USD.GBP USD.CHF USD.XAU
## 1962-01-02      NA      NA      NA      NA      NA      NA      NA      NA
## 1962-01-03      NA      NA      NA      NA      NA      NA      NA      NA
## 1962-01-04      NA      NA      NA      NA      NA      NA      NA      NA
## 1962-01-05      NA      NA      NA      NA      NA      NA      NA      NA
## 1962-01-08      NA      NA      NA      NA      NA      NA      NA      NA
## 1962-01-09      NA      NA      NA      NA      NA      NA      NA      NA
## 1962-01-10      NA      NA      NA      NA      NA      NA      NA      NA
## 1962-01-11      NA      NA      NA      NA      NA      NA      NA      NA
## 1962-01-12      NA      NA      NA      NA      NA      NA      NA      NA
## 1962-01-15      NA      NA      NA      NA      NA      NA      NA      NA
##            USD.XAG USD.XPT USD.BTC X10
## 1962-01-02      NA      NA      NA  NA
## 1962-01-03      NA      NA      NA  NA
## 1962-01-04      NA      NA      NA  NA
## 1962-01-05      NA      NA      NA  NA
## 1962-01-08      NA      NA      NA  NA
## 1962-01-09      NA      NA      NA  NA
## 1962-01-10      NA      NA      NA  NA
## 1962-01-11      NA      NA      NA  NA
## 1962-01-12      NA      NA      NA  NA
## 1962-01-15      NA      NA      NA  NA
tail(all.data[[1]],10)
##            DCOILWTICO DGS10 GSPC.Close FTSE.Close N225.Close USD.JPY
## 2014-09-21         NA    NA         NA         NA         NA   109.1
## 2014-09-22      91.46  2.57       1994       6774      16206   109.1
## 2014-09-23         NA  2.54       1983       6676         NA   108.9
## 2014-09-24         NA  2.57       1998       6706      16167   108.7
## 2014-09-25         NA  2.52       1966       6640      16374   108.8
## 2014-09-26         NA  2.54       1983       6649      16230   109.1
## 2014-09-27         NA    NA         NA         NA         NA   109.0
## 2014-09-28         NA    NA         NA         NA         NA   109.3
## 2014-09-29         NA    NA       1978       6647      16311   109.3
## 2014-09-30         NA    NA         NA         NA         NA   109.4
##            USD.EUR USD.AUD USD.NZD USD.ZAR USD.CAD USD.GBP USD.CHF
## 2014-09-21  0.7795   1.121   1.232   11.11   1.096  0.6141  0.9411
## 2014-09-22  0.7795   1.121   1.232   11.11   1.096  0.6141  0.9411
## 2014-09-23  0.7785   1.124   1.230   11.12   1.098  0.6121  0.9399
## 2014-09-24  0.7776   1.126   1.234   11.15   1.104  0.6107  0.9388
## 2014-09-25  0.7796   1.128   1.239   11.15   1.108  0.6106  0.9415
## 2014-09-26  0.7843   1.134   1.254   11.18   1.109  0.6129  0.9473
## 2014-09-27  0.7857   1.139   1.265   11.21   1.113  0.6138  0.9485
## 2014-09-28  0.7886   1.142   1.272   11.24   1.116  0.6155  0.9516
## 2014-09-29  0.7886   1.142   1.272   11.24   1.116  0.6155  0.9516
## 2014-09-30  0.7883   1.146   1.285   11.27   1.116  0.6158  0.9515
##              USD.XAU USD.XAG   USD.XPT  USD.BTC   X10
## 2014-09-21 0.0008229 0.05616 0.0007342 0.002464    NA
## 2014-09-22 0.0008229 0.05616 0.0007506 0.002511 0.535
## 2014-09-23 0.0008232 0.05652 0.0007553 0.002521    NA
## 2014-09-24 0.0008191 0.05625 0.0007507 0.002384 0.526
## 2014-09-25 0.0008190 0.05641 0.0007622 0.002312 0.521
## 2014-09-26 0.0008231 0.05698 0.0007622 0.002422 0.517
## 2014-09-27 0.0008193 0.05690 0.0007710 0.002478    NA
## 2014-09-28 0.0008212 0.05676 0.0007710 0.002501    NA
## 2014-09-29 0.0008212 0.05676 0.0007696 0.002574 0.522
## 2014-09-30 0.0008209 0.05700 0.0007686 0.002664    NA

Interest spread between Japan and USA

buf<-na.omit(all.data[[1]]$DGS10)-na.omit(all.data[[1]]$X10)
par(mfrow=c(1,1),mar=c(3,4,3,4))
buf<-buf[paste(first.date,"::",sep="")]
buf<-data.frame(date=as.Date(index(buf)),buf,row.names=NULL)
plot(x=buf[,1],y=buf[,2],type="o",main="Interest spread(%)",xlab="",ylab="Interest spread",xaxt="n")
axis.Date(side=1,at=seq(first(buf[,1]),last(buf[,1]),"days"),format="%Y/%m/%d")

plot of chunk unnamed-chunk-7