Annual Returns by State of the US Economy

[This article was first published on Timely Portfolio, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Sometimes it is fun to just look at annual returns, especially as the financial world has shifted its focus to microseconds in a world of inconceivable macro imbalances.  St. Louis Fed (USREC) offers a binary state of the economy with 1=recession and 0=expansion, but we all must remember that the assignment of the beginning and end dates of recessions occurs with a 1 to 2 year lag, so we cannot use them for real-time trading even at a monthly level.  However, we might be able to examine equity returns on a yearly level given the state of the economy in the previous year.  With a little ggplot2, I think a lot of folks might be surprised at a simple look at annual Dow Jones Industrial returns since 1921. In and around recessions, the market is either really right or really wrong.  Then in the last chart, my thought is that stocks will not be cheap again until we see a recession that lasts greater than 1 year.

For asset class returns by phase of the business cycle, there is a great article The Strategic and Tactical Value of Commodity Futures in the March/April 2006 Financial Analysts Journal that shows the following graph, which I have unfortunately not been able to replicate.

From TimelyPortfolio
From TimelyPortfolio
From TimelyPortfolio
From TimelyPortfolio
From TimelyPortfolio

R code:

#explore relationships of best years in US Stocks
#and recessions   require(quantmod)
require(ggplot2)
require(PerformanceAnalytics)
getSymbols("DJIA",src="FRED")  #get Dow Jones Industrials
getSymbols("USREC",src="FRED") #get US Recession(1)/Expansion(0)   
DJIA <- to.yearly(DJIA)[,4]
USREC <- to.yearly(USREC)[,4]   
#align dates as 12-31 of each year
#probably better way to do this but it works
index(DJIA) <- as.Date(paste(
	format(index(DJIA),"%Y-%m"),rep("-31",NROW(DJIA)),sep=""))
index(USREC) <- as.Date(paste(
	format(index(USREC),"%Y-%m"),rep("-31",NROW(USREC)),sep=""))     
stocks_economy <- na.omit(merge(
	lag(USREC,k=1),ROC(DJIA,n=1,type="discrete")))   
#I really like the boxplot by range, so let's do the same here
df <- as.data.frame(cbind(index(stocks_economy),
	coredata(stocks_economy)))
colnames(df) <- c("date","economy","DJIAreturn")
ggplot(df,aes(factor(economy),DJIAreturn)) +
	geom_boxplot(aes(colour = factor(economy))) +
	opts(title="Box Plot of DJIA Yearly Change by State of Economy Previous Year (recession=1)")     
m <- ggplot(df, aes(DJIAreturn, colour=factor(economy)) )
m + geom_density(size=1,aes(y = ..scaled..)) +
	opts(title="Density Plot of DJIA Yearly Change by State of Economy Previous Year (recession=1)")     
m <- ggplot(df, aes(y=DJIAreturn, x=factor(economy)) )
m + geom_point() + geom_rug() +
	opts(title="Marginal Rug Plot of DJIA Yearly Change by State of Economy Previous Year (recession=1)")     
chartSeries(runSum(USREC,n=10),theme="white",
	name="Years in Recession by Decade")

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

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)