Created
January 13, 2012 23:10
-
-
Save timelyportfolio/1609266 to your computer and use it in GitHub Desktop.
yen and us10y
This file contains hidden or 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
require(quantmod) | |
#get Japanese Yen daily from Fred http://research.stlouisfed.org/fred2 | |
getSymbols("DEXJPUS",src="FRED") | |
#get US 10y Yield from Fred | |
getSymbols("DGS10", src="FRED") | |
Yen10y <- na.omit(merge(DEXJPUS,DGS10)) | |
#define colors | |
#use derivative of indianred4 with alpha for Yen | |
rgbnum <- col2rgb("indianred4") | |
col.yen <- rgb(rgbnum[1],rgbnum[2],rgbnum[3],alpha=180,maxColorValue=255) | |
#use derivative of steelblue4 with alpha for US 10y | |
rgbnum <- col2rgb("steelblue4") | |
col.10y <- rgb(rgbnum[1],rgbnum[2],rgbnum[3],alpha=180,maxColorValue=255) | |
#2 rows and 1 column of graphs | |
par(mfrow=c(2,1)) | |
par(oma=c(0,1,0,0)) | |
opar <- par(mai = c(0, 0.8, 0.5, 0.8)) | |
#plot the Japanese Yen | |
plot.zoo(Yen10y[,1], type="l", | |
xaxt="n", xlab=NA, ylab="Yen (US$/JPY)", | |
col=col.yen, col.lab=col.yen, col.axis=col.yen, | |
lwd=3,bty="n",fg = "gray70") | |
#do grid for y | |
for (i in seq(par("yaxp")[1],par("yaxp")[2],by=(par("yaxp")[2]-par("yaxp")[1])/par("yaxp")[3])) { | |
abline(h=i, col="gray70") | |
} | |
title(main="Japanese Yen and US 10y Yield %",adj=0,outer=TRUE,line=-2) | |
par(new=TRUE) | |
plot.zoo(Yen10y[,2], type="l", | |
xaxt="n", yaxt="n", xlab=NA, ylab=NA, | |
col=col.10y, col.lab=col.10y, | |
lwd=3,bty="n",fg = "gray70") | |
axis(side=4,col.axis=col.10y,fg="gray70") | |
usr <- par("usr") | |
text(usr[2] + .12 * diff(usr[1:2]), mean(usr[3:4]), "US 10y Yield %", | |
srt = 90, xpd = TRUE, col = "steelblue4") | |
par(opar) | |
opar <- par(mai = c(0.8,0.8,0.2,0.8)) | |
#plot running correlation between yen and US 10y | |
plot.zoo(runCor(Yen10y[,1],Yen10y[,2],n=500), | |
xlab=NA, ylab = NA, | |
lwd=3,bty="n", | |
col.axis="gray30",col.lab="gray30",col="gray30",fg="gray30") | |
title(main="Rolling 2 Year Correlation", cex.main=0.9, adj=0, col.main="gray30") | |
for (i in seq(-1,1,by=1)) { | |
abline(h=i, col="gray70") | |
} | |
axis(side=4,labels=FALSE,fg="gray70") | |
par(opar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment