Historical Sources of Bond Returns with Shiller Data 1919-2011

April 11, 2011

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

And as usual, I always want a longer data set, so after a little playing with R-Excel, we can extend our historical sources of bond returns to 1919.  If nothing else, maybe you can find other uses for the Shiller Dataset in R.

From TimelyPortfolio

And as an added bonus, we can prepare a boxplot.

From TimelyPortfolio

As always, please criticize or make suggestions.


R code:


getSymbols(“BAA”,src=”FRED”) #load Corporate for credit from Fed Fred

#get Shiller data for inflation and US Treasury 10 year
URL <- “http://www.econ.yale.edu/~shiller/data/ie_data.xls”
shillerData <- read.xls(URL,sheet=”Data”,pattern=”Rate GS10″)
#strip out date(1), CPI(5), and GS10(7)
shillerData <- shillerData[,c(1,5,7)]
#get data starting in January 1919 to match with BAA xts series
shillerData <- shillerData[rownames(shillerData[which(shillerData$Date==format(index(BAA)[1],”%Y.%m”)):NROW(shillerData),]),2:3]
shillerData <- xts(shillerData[1:NROW(BAA),1:2],order.by=index(BAA))

#get 12 month CPI change


chart.TimeSeries(bondReturnSources,legend.loc=”bottom”,main=”Historical Sources of Bond Returns”,ylab=”Yield as %”,colorset=c(“cadetblue”,”darkolivegreen3″,”goldenrod”,”gray70″))
#add source as caption
mtext(“Source: Federal Reserve FRED and Robert Shiller”,side=1,adj=0)

chart.Boxplot(bondReturnSources,main=”Historical Sources of Bond Returns”,colorset=c(“cadetblue”,”darkolivegreen3″,”goldenrod”,”gray70″))
mtext(“Source: Federal Reserve FRED and Robert Shiller”,side=1,adj=0)

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.


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)