Monitoring Sources of Bond Return
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Here is a way to monitor bond return sources in R. In the next iteration, I will use CPI to add history to the series.
From TimelyPortfolio |
So right now, you can expect about a 5% return from bonds. How much of that is real return is unknown.
R code:
require(quantmod)
require(PerformanceAnalytics)
require(reshape2)
require(ggplot2)
getSymbols(“WGS10YR”,src=”FRED”) #load 10yTreasury
getSymbols(“WFII10″,src=”FRED”) #load 10yTIP for real return
getSymbols(“BAMLC0A0CM”,src=”FRED”) #load Corporate for credit
getSymbols(“CPIAUCSL”,src=”FRED”) #load Corporate for credit
bondReturnSources<-na.omit(merge(WGS10YR-WFII10,WFII10,to.weekly(BAMLC0A0CM)[,4])["2003::"])
colnames(bondReturnSources)<-c("10yTreasury","10yTIPReal","Credit")
bondReturnSourcesToGraph<-data.frame(cbind(as.Date(index(bondReturnSources)),coredata(bondReturnSources)))
colnames(bondReturnSourcesToGraph)<-c("Date","InflationBreakEven","10yTIPReal","Credit")
bondReturnSourcesToGraph<-melt(bondReturnSourcesToGraph,id.vars=1)
colnames(bondReturnSourcesToGraph)<-c("Date","ReturnSource","Yield")
rownames(bondReturnSourcesToGraph)<-c(1:NROW(bondReturnSourcesToGraph))
ggplot(bondReturnSourcesToGraph, stat=”identity”, aes(x=Date,y=Yield,fill=ReturnSource,group=ReturnSource)) + geom_area() +scale_x_date(format = “%Y”) + opts(title = “Sources of Bond Return”)
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.