**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”)

**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...