Annual Returns by State of the US Economy

June 1, 2011

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

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)
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(
index(USREC) <- as.Date(paste(
stocks_economy <- na.omit(merge(
#I really like the boxplot by range, so let's do the same here
df <-,
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)")    
name="Years in Recession by Decade")

Created by Pretty R at

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.


Mango solutions

RStudio homepage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training


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)