Back to Community
Classic RSI2 Mean-Reversion Strategy (SPY/TLT)

This is a simple mean-reversion strategy that uses the RSI2 technical indicator which was originally developed and popularized by Cesar Alvarez more than a decade ago. Most people are familiar with the RSI14 but the RSI2 is a much more powerful tool for short-term market timing that works well in both momentum and mean-reversion strtegies. The algorithm monitors the 2-day RSI of SPY (S&P500) and TLT (Long-Term US Treasury), both of which are well-known as mean-reverting assets. When an asset's RSI2 dips below 30 ("Oversold"), go long with 50% of the portfolio. When its RSI2 crosses above 70 ("Overbought"), sell the position and go to cash. The vanilla version of this strategy generates good risk-adjusted performance but still underperforms the S&P 500, for the most part. However, using leverage can increase the risk/reward profile in order to outperform the S&P 500 while still maintaining lower risk. I'm using 2x leverge for this strategy.

Clone Algorithm
139
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 587da02163a37c6155cb5670
There was a runtime error.
20 responses

Optimized version. Moved execution time to 15 minutes after open and changed Overbought/Oversold thresholds to 80/40.

Clone Algorithm
176
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 587dcfbb6585495df0fbb105
There was a runtime error.

"RSI2 technical indicator which was originally developed and popularized by Cesar Alvarez more than a decade ago."

It's funny how some people get credit from the work of others. The RSI was developed by J. Welles Wilder. Setting the period to 2 and calling this a new development sounds extremely weird. it's like setting the moving average period to 2 and claiming it your invention. It is so disconcerting that people in this industry do not have respect for intellectual property. At least Quantopian does a good job to offer credit to original work.

Now, a system with 26% max drawdown , leverage and NO stops is the ultimate NO NO. You have more chances going to a casino and betting all your money on a single roulette number. This system is NOT market neutral, repeat, not market neutral. If long SPY and there is flash crash but not long TLT, you can end up owing the broker multiples of your net worth.

I just wanted to share by opinions with you.

Now, a system with 26% max drawdown , leverage and NO stops is the ultimate NO NO. You have more chances going to a casino and betting all your money on a single roulette number. This system is NOT market neutral, repeat, not market neutral. If long SPY and there is flash crash but not long TLT, you can end up owing the broker multiples of your net worth.

This seems to be a pretty systemic issue on these forums. I think this algo is worth looking at and contains valuable information but like most algorithms here needs to enforce strict trading controls. I usually spend 95% of my time on an algo working on execution and risk control, 4% bug fixing, and 1% tuning parameters. Sometimes I will find an algo that I like here, spend a few days making it trade realistically only to find out that by doing so you remove all alpha and it's worthless. Getting unachievable returns doesn't help anyone. but I will say that this one is better than many

Ricardo,

Thank you for your comments on my system. There are a couple things I'd like to point out:

It's funny how some people get credit from the work of others. The RSI was developed by J. Welles Wilder. Setting the period to 2 and calling this a new development sounds extremely weird. it's like setting the moving average period to 2 and claiming it your invention. It is so disconcerting that people in this industry do not have respect for intellectual property. At least Quantopian does a good job to offer credit to original work.

I did not say that Cesar Alvarez developed the RSI. Everyone and their grandma in the quant community knows the RSI has been around for decades and was originally created by the legendary J. Welles Wilder. It was the particular technique of using a 2-period setting for the RSI that was popularized during the early 2000s by Cesar Alvarez, another quant legend who is also a good friend that lives near me. Notice that he did not rename it to the Alvarez RSI because he didn't change anything fundamental to the RSI's formula. Now on a different note, Cesar did help create another variation of the RSI called the "Connors RSI" while he was working under Larry Connors (yet another quant legend), but I digress.

Now, a system with 26% max drawdown , leverage and NO stops is the ultimate NO NO. You have more chances going to a casino and betting all your money on a single roulette number. This system is NOT market neutral, repeat, not market neutral. If long SPY and there is flash crash but not long TLT, you can end up owing the broker multiples of your net worth.

I did not claim this system was market neutral, nor did I recommend its use to anyone. I simply presented an interesting mean-reversion strategy that is extremely simple at its core to demonstrate the concept of using the RSI2 to generate trade signals. Obviously, if you wanted to trade this, you would need to add risk management techniques like hedging, using stop loss and/or scaling into positions, etc.

As for your Black Swan comments, please realize that:

1) I implied leverage was optional, not required. I even stated that the non-leveraged version would not outperform SPY. If you wanted to undertake the risk of using leverage to increase return then that's your call but that option is there. I wanted to show that even the 2x leveraged version has hypothetically outperformed SPY in the last 15 years while maintaining a similar level of volatility and even a smaller Max DD during 2008.

2) This system's base allocation to SPY is only 50%, so even at 2x leverage, your exposure to SPY is the same as if you were going to buy and hold the ETF with 100% of your account. If a Black Swan happens then the SPY portion is only going to suffer just as much as the ETF itself. Not to mention that there could also be an open TLT position at the same time that could potentially hedge the Black Swan (unless all correlation goes to 1 which means pretty much everyone is screwed anyway). I won't deny this simple system's vulnerability to a Black Swan event because if both SPY and TLT tank at the same time then yes, you could get wiped out, but so would many others in that kind of an event. That is why you diversify little bits of your money across many different systems/strategies to spread out your risk.

3) Unlike an SPY/TLT buy-and-hold strategy, this system is not in the market 100% of the times. In fact, if i recall correctly, it is exposed to either asset only about 50% of the time (gotta double check my numbers). So just statistically speaking, it automatically has half the odds of getting struck by a Black Swan.

If you have any ideas or improvements to add to this strategy to make it less risky then please feel free and contribute.

~Kory

Here's a strictly non-leveraged version with reasonable returns.

Clone Algorithm
87
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5880e82977ca4c474bbf2bc0
There was a runtime error.

Tim, when I run your algo with the PvR routine there is still leverage as buys happen before sells. When I update the code to ensure it looks for available cash before making purchases the returns are severely reduced.

@Kory thanks for this was looking into the 2 RSI myself when i found a post of it on trading view. I really don't understand some people on these forums, 25% DD is TOO MUCH, then invest in bonds, it blows my mind how a system that out performs the SPY, has half the DD of 08 and people complain, like what??? What system, or where on earth would you have been invested in 08 to get any sort of decent return and avoid 50% DD? Literally survived 08 beautifully made a profit in 08 lol, not to mention it has survived every single black swan to date in a superb manner.

Also, people talk about black swans, listen if a black swan event blows out your account guess what you are going to have much more important things to worry about like food, water, shelter, bullets, and not your worthless paper account which will probably be worth nothing through inflation, war, whatever.

Lastly, you can get leverage through many different methods don't require you owing money to your broker, options, futures, 2x-3x etfs.

Thanks, Tyler, very interesting. Would you be willing to post your version of the algorithm?

@Elsid Aliaj: I mostly agree with you, although a non-world-ending Black Swan like 1987 could cause major damage as well. The key word here is diversification across multiple strategies. Also, here's a tear sheet for the strategy:

Loading notebook preview...
Notebook previews are currently unavailable.

The common practice of recording context.account.leverage misses 389 of the 390 minutes of the trading day.
You can use https://www.quantopian.com/posts/max-intraday-leverage to avoid that mistake.

Yesterday's algo is worthwhile however it was said:

Here's a strictly non-leveraged version with reasonable returns.

It was actually leverage of 2 almost right away into the run, the 2.0 leverage intraday made real returns half of what is shown.
2017-01-17 06:31 pvr:122 INFO PvRp 0.0985 %/day 2003-01-02 to 2017-01-17 $20000 2017-01-22 02:10 US/Eastern
2017-01-17 06:31 pvr:123 INFO Profited 139226 on 39999 activated/transacted for PvR of 348.1%
2017-01-17 06:31 pvr:124 INFO QRet 696.13 PvR 348.07 CshLw -129115 MxLv 2.00 RskHi 39999 Shrts 0

@KORY

This was the strategy i found on tradingview, don't know how much of the ideas spoken about there you have applied but might be worthwhile to mess around with some of them.

https://www.tradingview.com/chart/CELG/EVXQPaR9-Larry-Connors-RSI-2-Trading-System-Surprising-Win-Rate/

The best goal would be to get the same returns and Drawdowns without TLT, the issue is what happens when we get a bear market in bonds, and correlations as safe heavens break down.

Nov 2017 update:

Clone Algorithm
59
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59fe0d304a4921441346f111
There was a runtime error.

@Kory

it would be better could help migration the strategy into Zipline, or where are you living trading now ?
Could you share your living trading experience .

I enjoyed reading various aspects of the debate this thread has produced, but I will pick up on just one aspect and that is the concept of the black swan event or, in other words, "your worst draw-down is still ahead somewhere, just waiting for you", and then go on to consider what to do about it?

Personally, with every system that I actually trade, I always like to run it through the whole period from 1980 until now. If it fails the "October '87 Crash" test, then it simply goes into the rubbish bin, irrespective of how good the rest of it looks. Some people say this is nonsense because, a) the markets are different now [yes, I agree], b) the Oct '87 crash will not repeat itself [yes I agree, and yes, "next time" will be different .... maybe even worse], and c) you must be a real old fossil to even care about pre-historic 1987 [yes, I am, and I was trading it actually, while the dinosaurs were running around shouting their heads off on the floor].

The point is, how can we get as wide as possible a range of real (not synthetic) data for building our systems / algos? Answer: use as much real historic data as possible, going back as far as possible, and taken from as many diverse markets as possible, even if they are not the same markets as we are really intending to trade. The fact that some market behavior actually happened in market X at some time in the past means that it is a possible market behavior that just might possibly be closely approximated by the behavior of our chosen market at some future time. The aim of using a lot of other market data is not necessarily because I want to build a "one system fits everything" model, but because I want to expose my systems / algos to as wide a range of possible market conditions as I can, to ensure they are robust.

Comments / agreement / disagreement ? ..... all welcome.

@Tony

Bravo, It seems Quantopian is made up of ADD Crypto currency chasing gains crowd, if you have been around the early current crypto community you know what I'm talking about. It just gamblers mentalities throughout majority of this community, mostly focused on VIX from 2010+ which is utter insanity. This strategy is one of the ones I like most, but again I don't like that fact that it depends on Bonds for sooooooo much of it's gains.

To truly test this I would run it from 86+ and then get proper bond data such as prices during % rate increases, given that even if rates go up bonds can still manage ok.

Theres a reason RenTech spends probably half or almost all their resources on Data gathering/cleanup, majority here think they can do better.

Elsid writes: "To truly test this I would run it from 86+ and then get proper bond data such as prices during % rate increases"
This is good advice and highlights several issues that some people might have forgotten, or perhaps were never even aware of, specifically:

  • Take a look at the S&P500 for the last 5 years --- its all Bull market except for a couple of little blips.
  • Go back as far as March 2009 --- its still all Bull market except for a few little blips.
  • That means anyone who has been trading for < about 8 years has never experienced anything except a bull market, so presumably they consider current market behavior and think: a) "This is normal" and b) The last 8 years is what "typical market behavior" looks like, and c) 8 years is more than enough for back-testing.[ a) No, it isn't, b) No, it doesn't , c) No, it's not].

  • OK, so then lets look back as far as 2007. Now at least we see a (brief) Bear market in the S&P500 (from Mid 2007 to March 2009) and so, if we can handle that, then we should be able to handle anything, right? Well, sorry, but I don't think so.

  • Take a look at the US 30year T-Bond ($TYX). Go back to 1988 and notice what you see. Sure it bumps up and down a bit, but the overall trend in bond yields is generally all down. We have been in a declining interest-rate environment for the last 30 YEARS!!! Declining interest rates means lower cost of borrowing and that drives business expansion, and this has been fueling the stockmarkets of the world for the past 30 years!! During that time, we do not have any experience of a rising interest rate environment that has lasted longer than about a year or so. Therefore, unless you believe that interest rates can actually continue on and on going down, then we are at the edge of "uncharted territory".

As a result, unless we have either been trading for > 30 years or have studied the behaviors of other markets, then we really cannot expect that everything we know (or think we know) about market behavior from the last 30 years will actually continue to hold in future, and certainly this problem is greatly exacerbated if all we know from our trading experience is just in the bull market of the last few years.

I think that Elsid writes wisely about the need to look back a considerable time, and especially about looking at rising (as well as falling) interest rate environments. We ignore his words about this at our peril.
Message: Whatever timeframes you are looking at now for development & testing, it would be wise to look at even longer ones.... preferably MUCH longer ones!

Hey Tony,

Yeah 87 is just a starting point would love to see data going back to the 70's and beyond with sky rocketing interest rates. Thing is though Data is the issue, I even posted on here about actual data issues from Quantopian's historical data actually being wrong for some days, and it was basically thrown under the bus well we have to sacrifice data to allow people to prototype their ideas faster whatever that means.

I'm not even a trading pro, but it seems this whole platform was set up very amateurishly if the goal was to research anything robust, given that a single data point failure yet alone multiple, could throw your whole hypothesis out of wack. I guess a good amount of people I know switched over to quantconnect for whatever multiple shortcomings Quantopian offered.

What we really needed was a almost perfect research environment, live trading, contests, allocations could of been developed outside of here if something showed true promise. Just glad someone else actually sees the value in Data creating something robust as opposed to just throwing money at it, even if it's a small allocation, what happens if 15 our of your 20 strategies all suffer massive drawdowns, still almost a blown account or insane drawdowns, because it looked great for the last 5-10 years.

I also don't buy the excuse of not being aware of things, especially in the day and age of Google, I was born in 87' not even in the US, it's just common sense for any person who studies markets at least somewhat. I've seen strategies on here that literally show a 1-2 year backtest, because going further completely blows the algorithm up. I just have no idea what peoples purposes of posting them is, it's not like they mention it hey does good, but has issues beyond this some try to pass it off as look how awesome this is.

Anyway rant over lol

Well, I'm a "new kid" on this (Quantopian) block and I don't know anything about the history of how things were set up here originally and I don't care to speculate or comment on that, but I certainly do agree that we need data going back as far as possible, at least for the major US stocks, indices and interest rates, some of which should certainly be available back as far as pre-1929. IMHO, notwithstanding all the limitations that one can think of, that old data provides some very useful long-term "calibration" points, despite the fact that some people might believe that anything pre- Janet Yellen's reign is too much like ancient history to be relevant anymore. As Warren Buffett says: "When the tide goes out, that's when we see who's been swimming naked". Well, the tide hasn't been out for a while (i.e. any extended period of rising interest rates). I don't know about seeing naked swimmers, but I'm sure that in due course we will see plenty of mud, and I certainly don't want to get stuck in it! I will ask about longer term historic data. Thanks for bringing up this issue. Cheers, Tony.

@Kory,
my apologies, it was not my intention to subvert this thread away from RSI2 to the topic of long-term data. As far as i'm concerned, please feel welcome to ask Dan to split the last few posts out into a separate thread if you want to.

@Dan,
I know some people might disagree, but I think the topic of long-term (i.e. multi-decade) data going back as far as possible is important when it comes to designing ROBUST trading systems / algos that will at least have a good chance of being able to stand up to significantly different market environments compared to what we have today. Please can you advise (either here or in a separate thread) how far back we actually have data for at least the Dow30 stocks, US indices, and Bonds, and any other long-term data sets? Best regards, Tony M.

Kory its a pretty solid strategy, having a maximum DD of 26% (about half of buy and hold) and blowing away buy and hold returns is nothing to sneeze at!