Category Archives: SPY

Backtesting Options: Selling SPY Puts on RSI(2)

Let’s try the good old strategy for RSI(2) mean reversion.
Buy on Rsi(2)<30
Sell on Rsi(2)>60
Execution is on the Open of the next day.
This is what trading the SPY etf looks like.

How about using the same signals and selling 10, 1-point away from the floor price, front month Puts.*
Again, we sell 10 Puts right below the SPY price. 
So if SPY is at 145.7 we would sell the (floor(145.7)-1) 144 strike Put.
We sell the front month before the 11th of the month, otherwise we shift to the next month.
We cover the position on an Rsi(2) sell signal or let it expire.
All Buy and sells are on the next day Close and on the ask for buy orders and bid for sell orders.**

Of course there are money management differences: The top chart reflects %-of-equity money management (hence, the compounding), while the bottom does not (it buys 10 contracts, rain or shine) . But otherwise, I am surprised at the similarity in the shape of the equity curve. Where is the extra time premium I would expect on buying the fear? 
How about selling further out of the money Puts. 1–>5 points away from the current price:

Similar results. Any thoughts?

*Many thanks to Dave. for his help.
**I will caution the reader that backtesting options is fairly involved and may contain errors including but not limited to: historical data errors, programming errors, underestimation of slippage and execution costs, unrealistic assumptions on price fills, etc. I use EOD data, so there is no information on the open/high/low of the day. 

CBA – Quick test drive

Inspiration strategy:

Quoted from
“We propose a model that is designed to identify bull-market and bear-market regimes. We examine correlation between stocks and bonds as a signal. Our hypothesis is that negative correlation between long bonds and stocks represents a bear-market regime, and a positive, or non-existent correlation, reflects a bull market regime.The model calculates rolling 90-day correlation estimates between the S&P 500 and long-bonds. At each month end, the model computes the 60-day MA of the correlation against the 600-day MA of the correlation. If positive, the model invests in risk; if negative, the model invests in riskless.”

I will do a different kind of implementation so my results will differ due to different data and different strategy. When referring to correlation I will be referring to the correlation of the SP500 to the inverse of the 10-year Treasury yield.

The system will either be long the SP500 or be in cash.
Each month it will look at the short and long term correlations and if stocks/bonds tend to be more correlated than usual, it buys the SP500. If not, it sells it and holds cash.

I will be using yahoo free data: ^GSPC (S&P500 Index) data as the “risk” asset and (1/ ^TNX, the reverse of the 10-year Treasury Yield) to represent long-bonds.

We ‘ll keep 2 parameters optimizable and lock the long moving average period to 600, to keep things simple.
Params [90,60]
a. CorelationPeriod (default=90)
b. MAshortPeriod (default=60)

Buy=MoreCorrelated=MA(Corr,MAshortPeriod )>MA(Corr,600);

 The above graph is using params [90,60]

Just for fun let’s do the exact opposite: We will buy when the short term correlation is less than the long term one. Same parameters.

Let us optimize the parameters to get a better sense of what is happening. Is there a “general acceptable area”?
params: [10–>300 10–>300]

There seems to be a “better” area of settings than the one we are using.
Let’s try the backtest with params [40 220]. In other words we are calculating correlation using a 2-month window. We are then comparing the almost yearly moving average of that to the 600-day longer term one.

Using these optimized parameters, what would trading the 5 core etfs would look like? Risk on means buy SPY,EEM,EFA and VNQ. Risk off means buy IEF.

The equity is for the whole 5 -asset system. The lower pane shows the Emerging Markets time series (NYSEARCA:EEM).
You can see from the lower graph, this system did not buy EEM for the whole 2010-2013 period.

Going back to just trading the SP500, what would happen if we added the simple MA rule. Buy as before but only if price is above it’s 200-day moving average. Sell as before but also sell if price is less than it’s 200 moving average:

Disclaimer: This is a quick and dirty try-out of whether stock/bond correlation can help differentiate bull/bear regimes. It’s not meant to be precise but rather to get you started in performing your own tests.

Few thoughts on TAA:
I will caution the reader that when it comes to “TAA” strategies, for the past few years, holding both the S&P500 (SPY) and bonds (IEF) was an exceptional strategy whether you timed it or not. That is mostly due to the fact that IEF, the 10-year treasury proxy had both an exceptional run and a fairly uncorrelated one to the stock index. As others have mentioned, TAA systems may have a hard time delivering if Treasury yields stop dropping (below zero..?). But one way to look at the typical TAA strategy is that it is a diversified “short-the-dollar” strategy. Looking at it that way, there is room to diversify to non -U.S. denominates assets.

The code in Amibroker:

/----Code by Sanz P.-----------------------------------------------------// 
MAperiods=Param("MA Periods",200,100,400,5);
Corrperiod=Optimize("corr Period",40,10,300,10);
MAshort=Optimize("MA short period",220,10,300,10);

Buy=MoreCorrelated AND newmonth;// AND abovema;
Sell=(!MoreCorrelated /*OR !abovema*/) AND newmonth;
Buy=!MoreCorrelated AND newmonth ;
Sell=MoreCorrelated AND newmonth;
PosQty =Param("How many Positions",1,1,20,1);
SetOption("MaxOpenPositions", PosQty );
PositionSize=-96/PosQty ;

Seasonals – SP500, Euro

Here’s the strategy:
Each month we buy at the Open of the first day of the month and sell at the close of the last day of the month.

Here’s the average profit loss for the S&P500 Etfs, SPY  (yahoo:SPY). Data from 1993.

This chart shows that for example if we bought every December @ the open and sold at the end of the month @the Close, we would average a 1.97% profit.
But is average profit, alone, a good indication of profit loss potential?

One way to look at this is his:
Mr. X., a french expat and a bon viveur, wakes up and just feels like gambling. He takes a trip to the nearby casino. We ‘ll call it the Casino “Royale”. He enters the lobby and is presented with 12 different slot machines.

Mr. Francois is the oldest employee of the Royale and has been there since the very beginning. His job is to record the history of those machines. How many times each paid off and how much. 
Mr. X and Francois are buddies. So Mr. X has access to Francois’ notes. 
Francois keeps telling Mr. X, that past does not guarantee the future: If machine #3 paid off 100% of the times it was played, does not mean that it will pay off the next one.
But if it did, if the winning rates and payoffs were “stable”, ie, we expected future statistics to be similar to past statistics, which machine should Mr. X choose and how much should he bet?
The answer to both is the Kelly criterion: f=(bp-q)/b

f* is the fraction of the current bankroll to wager;
b is the net odds received on the wager (“b to 1”); i.e., if you play $1, how much do I win/loose.
p is the probability of winning;
q is the probability of losing, which is 1 − p.

The bigger the probability of winning and the bigger the money paid per $1 bet, the bigger Kelly becomes. . Which only makes sense since we want to play games with big winning percentages and large payoffs. So we can use Kelly as an “indicator” to tell us what would be our “best” bet.

So again, here’s the SPY chart using Kelly instead of Average Profit.

For December here are the stats:

NumOfwins[12]: 14     – i.e., 14 Decembers were wins
NumOfloss[12]: 6        – i.e., 6 Decembers were losers
AvgWin[12]: 2.6075
AvgLoss[12]: -2.02946
Certainty[12]: 70             – i.e. 14 winning Dec’s out of 20 = 70% winning prob.
EXPECT[12]: 1.21641
KELLY[12]: 0.466505

So now that we got all that out of the way, here’s a longer term chart for the SP500 (^GSPC) with data since 1960:
Here you can visually see where the “sell in May and go away” saying comes from. Again, this is historical stats. Doesn’t mean they predict the future.
Probably all this is known to you: The best months to have invested on the SPY are November and December and the worst are May to October. 
And why am I posting this now? It’s already the end of December…
So here’s another seasonal for my European friends that have lost much of their purchasing power over the last 2 years.
This is the Euro (using the Futures prices, since 1995). Keep in mind that the Euro has had a bullish bias through most of it’s history. But look at January:

Approximate continuous “averaged” EURO graph Jan. to Dec

Past returns may not be indicative of  future returns.

Connors RSI – Part 1

One of the readers of this blog, Mark, alerted me to a new indicator/system published from Connors/Alvarez : The ConnorsRSI.

What is the ConnorsRSI?

It consists of three components:
a. Short term Relative Strength, i.e., RSI(3).
b. Counting consecutive up and down days (streaks) and “normalizing” the data using RSI(streak,2). The result is a bounded, 0-100  indicator.
c. Magnitude of the move (percentage-wise) in relation to previous moves. This is measured using the percentRank() function.

The formula given is:
ConnorsRSI(3,2,100) = [ RSI(Close,3) + RSI(Streak,2) + PercentRank(percentMove,100) ] / 3

Bottom line: Connors/Alvarez have used similar indicators in the past. What is happening here is that they are creating a more robust indicator by averaging the three. They are “normalizing” the three indicators (rsi, consecutive moves and magnitude of move) to a 0-100 range and then averaging.

Connors/Alvarez propose a strategy that uses the Connors RSI coupled with other rules and filters on large section of U.S. Stocks.
In this post we’ll test the indicator on one security only, the SPY etf (as a proxy for the SP500).

Test A –
Instrument – SPY
1. Using ConnorsRSI(3,2,100) – We ‘ll call it Crsi.
2. Buy on Crsi<15
3. Sell on Crsi>70
4. Buy /Sell on the next bar Open price.
5. Commision of $0.005.

Test B –
The obvious question is whether the parameters are “fitted” to the data. What about using other parameters:
BuyThreshold –>5-50
BuyThreshold –>50-95

Test C –
What about before 1994? We ‘ll use ^GSPC (the SP500 Index).
Same parameters as “Test A”

Detailed results Test A

All trades
Initial capital 100000
Ending capital 336322.84
Net Profit 236322.84
Net Profit % 236.32%
Exposure % 6.55%
Net Risk Adjusted Return % 3606.42%
Annual Return % 6.30%
Risk Adjusted Return % 96.17%

All trades 179
Avg. Profit/Loss 1320.24
Avg. Profit/Loss % 0.73%
Avg. Bars Held 4.77

Winners 136 (75.98 %)
Total Profit 439687.37
Avg. Profit 3233
Avg. Profit % 1.71%
Avg. Bars Held 3.93
Max. Consecutive 11
Largest win 15964.53
# bars in largest win 3

Losers 43 (24.02 %)
Total Loss -203364.52
Avg. Loss -4729.41
Avg. Loss % -2.37%
Avg. Bars Held 7.42
Max. Consecutive 3
Largest loss -35059.29
# bars in largest loss 10

Max. trade drawdown -58157.34
Max. trade % drawdown -23.75%
Max. system drawdown -58157.34
Max. system % drawdown -23.28%
Recovery Factor 4.06
CAR/MaxDD 0.27
RAR/MaxDD 4.13
Profit Factor 2.16
Payoff Ratio 0.68
Standard Error 20256.9
Risk-Reward Ratio 0.5
Ulcer Index 3.5
Ulcer Performance Index 0.26
Sharpe Ratio of trades 2.23
K-Ratio 0.0404

Better than mean-reversion? An Adaptive Multi-Strategy System

Mean reversion strategies have been very popular since 2009. They have performed exceptionally well for the past 10 years, performing well even during the 2008-09 bear market. Different versions have been popularized, notably by Larry Connors and Cezar Alvarez (previous post) as well as many others in the blog-o-spere such as David Varadi of CSS analytics (DV2) and Michael Stokes @ MarketSci. Some use the RSI indicator, some use a short term simple moving average, some use boillinger bands, etc. The concept is the same: If price moved up  today, it will tend to revert (come down) tomorrow.

Here’s a couple of simple mean reverting strategies using a short term RSI (Relative Strength Index) , trading the ^GSPC index. They buy on oversold and sell on overbought. Long only.

Looks nice, doesn’t it? We barely see the 2008-2009 draw-down that  Buy-N-Hold suffered.
There is a “but”…

Look at the same strategy starting in 1960:


This is telling us that for the last 10 years the market has changed and has become mean reverting. There might be fundamental reasons for this and although it is unlikely the market will return to pre-2000 behavior, it is not inconceivable.

Let’s say we traded the oposite strategy. Buy if short term RSI is high, sell if it’s low.

As expected, it does well up to 2000, then it’s a disaster. Notice that for the period 2010-2012, it has not performed as badly as expected. Others on the blog-o-spere have mentioned this: Mean-reverting strategies have not performed as well starting 2010.

So knowing what we now know, how would an adaptive strategy work.

The Master strategy Includes:
A. 6 Mean Reversion strategies:
Instead of deciding on which RSI period and thresholds to use, we use 6 different versions (RSI(2), RSI(3) and RSI(4), each with different thresholds).
2. One Non-Mean-Revting strategy: If RSI(2) crosses 50 up then buy. If it crosses below, sell.

Allocation Rules:
We measure risk adjusted performance for the last 600 bars for each of the 7 strategies. The top 5 get allocated capital;
Best gets 50% of account to trade with
2nd gets 40. 3rd gets 30, etc.
Total allocation is 150%, meaning if all strategies were trading we would have to use 1.5x leverage.

In the second pane, the graph represents positions taken by the trend-following strategy.
In the third pane, the graphs represent positions taken by the various mean reverting strategies.

Up to 2002 the system takes positions mostly in the trend following strategy while starting as early as 1996 mean-reverting strategies start increasing positions and eventually take over by 2004.
Keep in mind that although the graph looks great, there is a 3 year period (2000-2003) of continuous draw-down as the environment changes and the strategy tries to adapt.

You may also notice that the “trend-following” RSI strategy (buy on up, sell on down) briefly started traded in August 2011, after being inactive for 9 years… Something to think about.