Tuesday, October 16, 2012

Japanese Government Bond (JGB) Data Since 1974

The Ministry of Finance Japan very generously provides data on JGBs back to 1974.  Here is a quick example how to pull it into R and then graph it.

From TimelyPortfolio

R code in GIST (do raw for copy/paste):

#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")
view raw jgb data.r hosted with ❤ by GitHub

1 comment:

  1. As with most everything in economics, demand is the price setter. Demand for moolah is determined, in the limit, by technological progress, i.e. the real rate of return on physical investment is what creates the demand for moolah. It's no secret that Western corporations have, on the whole, run out of investment opportunities. Some, if you Google it, even admit it. Since "savers" can't eat cash, the return falls to what the physical investments can generate. Right now, it ain't much. Thus the flight to fiduciary investment, where the return is more subject to fiddling by the "system".

    ReplyDelete