public
Created

japanese governement bond jgb historical data

  • Download Gist
jgb data.r
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#get Japan yield data from the Ministry of Finance Japan
#data goes back to 1974
 
require(latticeExtra)
require(xtsExtra)
 
url <- "http://www.mof.go.jp/english/jgbs/reference/interest_rate/"
filenames <- paste("jgbcme",c("","_2010","_2000-2009","_1990-1999","_1980-1989","_1974-1979"),".csv",sep="")
 
#load all data and combine into one jgb data.frame
jgb <- read.csv(paste(url,filenames[1],sep=""),stringsAsFactors=FALSE)
for (i in 2:length(filenames)) {
jgb <- rbind(jgb,read.csv(paste(url,"/historical/",filenames[i],sep=""),stringsAsFactors=FALSE))
}
 
#now clean up the jgb data.frame to make a jgb xts
jgb.xts <- as.xts(data.matrix(jgb[,2:NCOL(jgb)]),order.by=as.Date(jgb[,1]))
 
plot.xts(jgb.xts,ylim=c(0,12),screens=1,las=1)
plot.xts(jgb.xts,ylim=c(0,12),screens=c(rep(1,5),rep(2,5),rep(3,5)),las=1)
 
#use lattice to do the same thing
#for the sake of time will do final formatting here
xyplot(jgb.xts,col=brewer.pal("Blues",n=9)[5:9],
ylim=c(0,12),
screens=c(rep(1,5),rep(2,5),rep(3,5)),
lattice.options=theEconomist.opts(),
par.settings=theEconomist.theme(box="transparent"),
scale=list(y=list(rot=0)),
strip=strip.custom(factor.levels=c("1-5 Year","5-10 Year","10-40 Year"),style=5),
main="Japanese Government Bonds Since 1974")

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.