Historical Sources of Bond Returns

April 11, 2011
By

(This article was first published on Timely Portfolio, and kindly contributed to R-bloggers)

As promised in Monitoring Sources of Bond Return, we can show more history if we use CPI instead of expected inflation (from the TIP inflation breakeven yield).  Here are the results with history back to 1953.

From TimelyPortfolio

However, more history includes negative inflation, so I think the chart is a little more clear with a PerformanceAnalytics chart.TimeSeries graph.

From TimelyPortfolio

 

R code:

require(quantmod)
require(PerformanceAnalytics)
require(reshape2)
require(ggplot2)

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″))
#use this for stacked bar, but comes out strange with too many months
#chart.StackedBar(bondReturnSources[“1953::”],main=”Historical Sources of Bond Returns”,ylab=”Yield as %”,colorset=c(“darkgreen”,”red”,”blue”))

#use ggplot for consistency with previous plot, but negative makes chart hard to read
bondReturnSourcesToGraph<-data.frame(cbind(as.Date(index(bondReturnSources)),coredata(bondReturnSources[,1:3])))
colnames(bondReturnSourcesToGraph)<-c(“Date”,”Inflation”,”Credit”,”Real”)
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 = “Historical Sources of Bond Return”)

To leave a comment for the author, please follow the link and comment on their blog: Timely Portfolio.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , ,

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training



http://www.eoda.de







ODSC

ODSC

CRC R books series











Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)