Skip to content

Instantly share code, notes, and snippets.

@timelyportfolio
Created January 30, 2013 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timelyportfolio/4676644 to your computer and use it in GitHub Desktop.
Save timelyportfolio/4676644 to your computer and use it in GitHub Desktop.
require(latticeExtra)
require(directlabels)
require(reshape2)
require(quantmod)
getSymbols("VUSTX",from="1990-01-01")
getSymbols("VBMFX",from="1990-01-01")
bonds.tr <- merge(ROC(VUSTX[,6],250),ROC(VBMFX[,6],250))
colnames(bonds.tr) <- c("VanguardLongTsy","VanguardTotBnd")
bonds.melt <- melt(as.data.frame(cbind(as.Date(index(bonds.tr)),coredata(bonds.tr))),id.vars=1)
colnames(bonds.melt) <- c("date","fund","totret250")
bonds.melt$date <- as.Date(bonds.melt$date)
asTheEconomist(
horizonplot(totret250~date|fund,origin=0,horizonscale=0.05,
data=bonds.melt,
strip=TRUE,strip.left=FALSE,par.strip.text=list(cex=1.1),
layout=c(1,2),
main="Vanguard Bond Funds 250 Day Total Return"))
direct.label(
xyplot(bonds.tr,screens=1,
ylim=c(-0.35,0.35),scales=list(y=list(rot=0)),
col=theEconomist.theme()$superpose.line$col,
par.settings=theEconomist.theme(box="transparent"),
lattice.options=theEconomist.opts(),
xlab=NULL,
main="Vanguard Bond Funds 250 Day Total Return"),
list("last.points",hjust=1,cex=1.2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment