**Quintuitive » R**, 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.

Last week was brutal for pretty much all markets. Surprisingly, it was bad even for the US dollar. The sharp and straight downward move was reminiscent of the descent of 2011. It’s time to review where does the major index stands from technical point of view.

Let’s start with a visual inspection.

Clearly the 200-day moving average is gone. In fact, it was Thursday which closed below it. On it’s own, it doesn’t mean much – one should also take into account when the eventual entry occurs. For instance, it’s obvious from this chart that the previous two signals from this average were whipsaws, which ended up losing money compared to buy and hold.

The other moving average is the 150-day. The reason it’s plotted is because it works reasonably well (for such a simple indicator) as a long-term indicator in mean reversion strategies. In other words, long trades are considered only if the price is above, short trades only if the price is below. Based on that – we are in “short the rallies” mode right now.

Let’s take a look at some number then:

require(quantmod) # Download data spy = getSymbols("SPY",from="1900-01-01",auto.assign=F) # Confirm the SMA situation first spy.sma = runMean(Cl(spy), 200) mm = merge(Cl(spy), spy.sma, all=F) ind = mm[,1] >= mm[,2] print(tail(ind,4)) # 2015-08-18 TRUE # 2015-08-19 TRUE # 2015-08-20 FALSE # 2015-08-21 FALSE # Yep, sell on the Thu's close # Compute the returns rets = ROC(Cl(spy),type="discrete") # Compute the adjusted returns adj.rets = rets/sqrt(runSum(rets*rets,10)/9) # The moving average sma = runMean(adj.rets,n=200) ind = sma >= 0 print(tail(ind,4)) # 2015-08-18 TRUE # 2015-08-19 TRUE # 2015-08-20 FALSE # 2015-08-21 FALSE # Yep, sell on the Thu's close # The standard deviation stddev = sqrt(runSum(adj.rets*adj.rets,200)/199) lower.band = -0.05*stddev ind = sma < lower.band print(tail(ind,4)) # 2015-08-18 FALSE # 2015-08-19 FALSE # 2015-08-20 FALSE # 2015-08-21 FALSE # Nope, no signal yet from this conservative version

Using the 200-day moving average both on the price and on the returns yields the same result – out. Only the system introduced in this post hasn’t triggered a signal yet, but it’s quite conservative by design.

How bad can it get? My answer is very, don’t even try to contemplate it. In severe downturns, like 2008 and in 2011, it is extremely painful to sit on the winning long positions, while the market is relentlessly shaving off points. To me it’s a much better approach to sit it out. And if I feel like doing something – small (volatility adjusted), short-term positions are the way to go. Just my two cents.

The post Where Does the S&P 500 Stand? appeared first on Quintuitive.

**leave a comment**for the author, please follow the link and comment on their blog:

**Quintuitive » R**.

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.