public
Created

  • Download Gist
yen and jgb context.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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#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]))
 
#get Yen from the Fed
getSymbols("DEXJPUS",src="FRED")
 
p1986 <- xyplot(na.omit(merge(DEXJPUS,jgb.xts[,"X10"])),
lattice.options=theEconomist.opts(),
par.settings=theEconomist.theme(box="transparent"),
scale=list(y=list(rot=0)),
strip=strip.custom(factor.levels=c("USD/Yen","JGB 10y Yield","Rolling 1Y Correlation")),
xlab=NULL,
main="Japanese JGB 10Y Yield and Yen Since 1986")
 
p2005 <- xyplot(na.omit(merge(DEXJPUS,jgb.xts[,"X10"]))["2005::",],
lattice.options=theEconomist.opts(),
par.settings=theEconomist.theme(box="transparent"),
scale=list(y=list(rot=0)),
strip=strip.custom(factor.levels=c("USD/Yen","JGB 10y Yield","Rolling 1Y Correlation")),
xlab=NULL,
main="Japanese JGB 10Y Yield and Yen Since 2005")
 
p2012 <- xyplot(na.omit(merge(DEXJPUS,jgb.xts[,"X10"]))["2012::",],
lattice.options=theEconomist.opts(),
par.settings=theEconomist.theme(box="transparent"),
scale=list(y=list(rot=0)),
strip=strip.custom(factor.levels=c("USD/Yen","JGB 10y Yield")),
xlab=NULL,
main="Japanese JGB 10Y Yield and Yen Since 2012")
#######print top to bottom
print(p2012,position=c(0,0,1,0.35),more=TRUE)
print(p2005,position=c(0,0.33,1,0.67),more=TRUE)
print(p1986,position=c(0,0.66,1,1))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.