Created
January 12, 2012 16:35
-
-
Save timelyportfolio/1601483 to your computer and use it in GitHub Desktop.
Source of Bond Return
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) | |
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