The Bear is Here

[This article was first published on R – Quintuitive, 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.

October and December have been devastating for stocks. It wasn’t until Friday though that we officially reached the depths of a bear market.

There are different theories, the most common is 20% pullback in an index. As readers of this blog are aware, I follow a slightly different definition, based on Jack Schannep’s work. Based on this definition, a bear market is official when two of the three major indexes (Dow Jones Industrial, S&P 500 and Dow Jones Transportation) reach a 16% decline of the most recent high. For the mathematically inclined, the 16% is not random – simply it takes about 19% gain off the bottom of a 16% decline to reach the same level. Thus, a bear market is official at 16%, and a bull market – at 19%.

Friday was significant on these metrics. Here is the situation on the S&P 500:

require(quantmod)
require(PerformanceAnalytics)

sp = getSymbols("^GSPC", from="1900-01-01", auto.assign=F)
sp.ret = ROC(Cl(sp), type="discrete")
table.Drawdowns(sp.ret["2008/"], top=5)

This has the following output:

The current pullback is the first 16+% correction since 2008. The story is the same on the Dow Jones Industrial:

And slightly different on the Down Jones Transportation:

This is certainly the most cherished bear market in US history, but that won’t make it less painful or less damaging. A recession does not always follow a bear market, but does quite often. How often – check Jack Schannep’s book. There are a few interesting statistics, like the average bear market decline and duration. Let’s take the S&P 500 (history from 1950) and do the math:

dd = table.Drawdowns(sp.ret, top=20)
print(dd)
# A visual inspection shows that we
# 11 previous bear markets 
mean(head(dd, 11)[,'Depth'])
# [1] -0.3288091 - 33%
median(head(dd, 11)[,'Depth'])
# [1] -0.2797 - 28%
max(head(dd, 11)[,'Depth'])
# [1] -0.1934 - 19%

A gloomy picture. The average bear market is 33%, the median bear market – 28% and the smallest – 19%. In other words, if history repeats itself, there is more pain to come. Significantly more on average.

The last piece of the puzzle (mine puzzle, Jack Schannep has a lot more), is to check the market for oversold signs. For this, Schannep has proposed a simple, yet powerful, indicator to forecast market bottoms. It was extremely precise in the 2011 pullback. Here is the code:

capitulation = function(spx=NULL, dji=NULL, nyse=NULL)
{
  require(quantmod)

  spx = if(is.null(spx)) na.fill(Ad(getSymbols("^GSPC", from="1900-01-01", auto.assign=F)), "extend")  else spx
  dji = if(is.null(dji)) na.fill(Ad(getSymbols("^DJI", from="1900-01-01", auto.assign=F)), "extend") else dji
  nyse = if(is.null(nyse)) na.fill(Ad(getSymbols("^NYA", from="1900-01-01", auto.assign=F)), "extend") else nyse
  
  spx.macd = MACD(spx, nFast=1, nSlow=50, maType=EMA)
  dji.macd = MACD(dji, nFast=1, nSlow=50, maType=EMA)
  nyse.macd = MACD(nyse, nFast=1, nSlow=50, maType=EMA)
  
  merged = merge(spx.macd[,1], dji.macd[,1], nyse.macd[,1], spx, dji, nyse, all=FALSE)
  merged = cbind(ifelse(merged[,1] <= -10 & merged[,2] <= -10 & merged[,3] <= -10, 1, 0), merged)
  colnames(merged) = c("ind", "spx.ind", "dji.ind", "nyse.ind", "spx.close", "dji.close", "nyse.close")
  
  capitulation = merged[merged[,1] == 1,2:NCOL(merged)]
  
  return(list(capitulation=capitulation, details=merged))
}
cap = capitulation()
tail(cap$capitulation)
#              spx.ind   dji.ind  nyse.ind spx.close dji.close nyse.close
# 2009-03-05 -16.48942 -16.15225 -16.95556    682.55   6594.44    4267.60
# 2009-03-06 -15.84705 -15.21571 -16.07971    683.38   6626.94    4284.49
# 2009-03-09 -16.14169 -15.70102 -16.65649    676.53   6547.05    4226.31
# 2009-03-10 -10.42353 -10.43552 -10.87757    719.60   6926.49    4499.38
# 2011-08-08 -13.47900 -11.42400 -14.88095   1119.46  10809.85    6895.97
# 2011-08-10 -12.61128 -11.47501 -11.57217   1120.76  10719.94    7101.24

The above table shows that there is no extreme selling in the current recess. All in all – more troubles ahead.

The post The Bear is Here appeared first on Quintuitive.

To leave a comment for the author, please follow the link and comment on their blog: R – Quintuitive.

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)