Bonds Risk and Return by Rating

June 27, 2011

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

As an extension to the Bond Market as a Casino Game series and Historical Sources of Bond Returns-Comparison of Daily to Monthly, I thought a ggplot of risk and return by decade and Moody’s Rating might be helpful.  Anyone who has read those other posts know that my opinion of bonds Guaranteed Failure with Bonds is not very favorable, and this is just another illustration that bond returns 1980-2011 are extremely abnormal and are mathematically impossible now.

From TimelyPortfolio


R code (click to download):

#do everything twice to compare monthly average to daily    require(RQuantLib)
require(ggplot2)   getSymbols("AAA",src="FRED") # load Moody's AAA from Fed Fred
getSymbols("BAA",src="FRED") # load Moody's BAA from Fed Fred    #Fed monthly series of yields is the monthly average of daily yields
#set index to yyyy-mm-dd format rather than to.monthly mmm yyy for better merging later
BAApricereturn<-BAA   AAApricereturn[1,1]<-0
colnames(AAApricereturn)<-"PriceReturn-monthly avg AAA"
colnames(BAApricereturn)<-"PriceReturn-monthly avg BAA"
#use quantlib to price the AAA and BAA bonds from monthly yields
#AAA and BAA series are 20-30 year bonds so will advance date by 25 years
for (i in 1:(NROW(AAA)-1)) {
maturityDate= advance("UnitedStates/GovernmentBond", Sys.Date(), 25, 3),
for (i in 1:(NROW(BAA)-1)) {
maturityDate= advance("UnitedStates/GovernmentBond", Sys.Date(), 25, 3),
}   #total return will be the price return + yield/12 for one month
colnames(AAAtotalreturn)<-"TotalReturn-monthly avg AAA"
colnames(BAAtotalreturn)<-"TotalReturn-monthly avg BAA"   charts.PerformanceSummary(merge(AAApricereturn,AAAtotalreturn,BAApricereturn,BAAtotalreturn),ylog=TRUE,
main="Simulated Returns from Moody's AAA and BAA Yield")
mtext("Source: Federal Reserve FRED",side=1,adj=0)   AAA_BAA <- na.omit(merge(AAAtotalreturn,BAAtotalreturn))
#get df for ggplot
df <-,coredata(AAA_BAA[,1:2])))
df[,1] <- paste(substr(format(as.Date(df[,1]),"%Y"),1,3),0,sep="")
colnames(df) <- c("Decade","AAA","BAA")
dfmelt <- melt(df,id.vars=1)
colnames(dfmelt) <- c("Decade","Moodys_Rating","TotalReturn")
dfsum <- ddply(dfmelt, .(Decade,Moodys_Rating), summarise,
mean = mean(TotalReturn),
sd = sd(TotalReturn))
jpeg(filename="risk and return by rating.jpg",quality=100,width=6.25, height = 5,
ggplot(dfsum, aes(x=sd,y=mean,label=factor(Decade))) + geom_point(aes(colour=Moodys_Rating)) +
geom_line(aes(x=sd,y=mean,colour=Moodys_Rating)) + geom_text(aes(colour=Moodys_Rating)) +
opts(title="Risk (sd) and Return (mean) by Moodys Rating since 1919")     ####some other experimentation but not part of blog post
#convert to monthly and get monthly returns
DJTA <- ROC(to.monthly(DJTA)[,4],n=1,type="discrete")
DJIA <- ROC(to.monthly(DJIA)[,4],n=1,type="discrete")
#set index to yyyy-mm-dd format rather than to.monthly mmm yyy for better merging later
index(DJIA)<-as.Date(index(DJIA))   #merge AAA,BAA,DJTA,DJIA
assetReturns <- na.omit(merge(AAAtotalreturn,BAAtotalreturn,DJTA,DJIA))   charts.PerformanceSummary(assetReturns,ylog=TRUE,
main="DJIA, DJTA, and Simulated Returns from Moody's AAA and BAA Yield")
mtext("Source: Federal Reserve FRED",side=1,adj=0)   chart.RiskReturnScatter(assetReturns["1950::1959",])

To leave a comment for the author, please follow the link and comment on their blog: Timely Portfolio. 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.

Search R-bloggers


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)