Skip to content

Instantly share code, notes, and snippets.

@timelyportfolio
Created January 12, 2012 16:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save timelyportfolio/1601483 to your computer and use it in GitHub Desktop.
Source of Bond Return
require(quantmod)
require(PerformanceAnalytics)
require(lattice)
require(latticeExtra)
getSymbols("GS10",src="FRED") #load 10yTreasury
getSymbols("BAA",src="FRED") #load Corporate for credit
getSymbols("CPIAUCSL",src="FRED") #load CPI for inflation
bondReturnSources<-na.omit(merge(ROC(CPIAUCSL,12,type="discrete")*100,
BAA-GS10,GS10-ROC(CPIAUCSL,12,type="discrete")*100))
bondReturnSources<-merge(bondReturnSources,
bondReturnSources[,1]+bondReturnSources[,2]+bondReturnSources[,3]) #add for total
colnames(bondReturnSources)<-c("Inflation","Credit","Real","Total")
chart.TimeSeries(bondReturnSources,legend.loc="bottom",
main="Historical Sources of Bond Returns",
ylab="Yield as %",
colorset=c("darkolivegreen3","cadetblue","goldenrod","gray70"))
xyplot(bondReturnSources,
col = c("darkolivegreen3","cadetblue","goldenrod","gray70"),
lwd = 3,
par.settings = theEconomist.theme(box = "transparent"),
lattice.options = theEconomist.opts(),
main = "Sources of US Bond Returns")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment