Japanese Government Bond (JGB) Data Since 1974
[This article was first published on Timely Portfolio, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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") | |
To leave a comment for the author, please follow the link and comment on their blog: Timely Portfolio.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.