Today’s topic is on finding the optimal periodicity for the RSI indicator and the techniques should apply to other sorts of indicators as well. The good news is that it won’t require any rocket science. John Ehlers has written a lot about this topic, and his articles spurred my interest in the topic, which frankly I had never considered. I might should note now that I have not reviewed the actual methodology that Ehlers used in any depth but my impression was that the methods were very advanced. But, I realized I could tackle this problem using just basic statistics.
Before we start analyzing specific solutions, I want to take a moment to describe what we are actually attempting to do. The question that we are trying to answer is how do we find the optimal length to use when calculating an indicator. A poor length value may result in the RSI spending too much time in either the overbought or oversold states or failing to reach the proper levels. Obviously, the optimal look back will change as market conditions change and therefore our methods should be adaptive and responsive to the market.
The goal is to find a metric to rank how well behaved the RSI is. A well behaved RSI is one that spends about an equal amount of time in overbought and oversold levels. During a trending market, if the RSI gets stuck into overbought conditions then that would be an example of a poorly behaved RSI. The solution thus is simply to measure the amount of time that the RSI spends in overbought and oversold conditions. My original inspiration came from the idea of a histogram. We simply add 1 for every bar that the RSI is above our threshold and subtract 1 for every bar that the RSI is below our threshold. The absolute value of the resulting summation is our error metric, which we seek to minimize.
Key Concept: Sum the amount of time that the RSI spends above 50 and below 50 and take the difference. The absolute value of the difference is our error metric, which we seek to minimize.
Next, we will simply compute our error metric for every RSI length in our search space, and select the RSI with the minimum error. In this example, I searched from RSI(2) to RSI(14). There is one more consideration which is determining our lookback. Too short a lookback will lack statistical relevance while too long a lookback will defeat the benefits of adaptation. Some manual trial and error was used before I settled on a lookback of 90 days.
We conducted the test using the S&P 500 Emini and have selected the long only RSI(2) with standard 30/70 overbought/sold thresholds as our baseline. The results are below:
RSI(2) Simple vs RSI(2..14) 50/50
|@ES Daily 1/1/2004-1/29/2017|
|RSI(2) Simple||RSI(2..14) 50/50|
|Avg Profit Per Trade:||$304.15||$363.21|
|Number of Trades||283||228|
While the results are not too different, we do see our profit factor and average profit per trade has improved. The net profit is slightly reduced and the drawdown slightly higher but essentially similar.
Tightening The Threshold
We can get better results by making our threshold more restrictive. Instead of using the median line, we can use the amount of time that our indicator spends in actual overbought and oversold levels. This makes some sense as the overbought/sold conditions are what’s really important. We use the same technique but now we try to balance the amount of time we spend below 30 and above 70. We see significantly better results. The results improve even more when we try to balance the extreme overbought/oversold conditions using 20/80 as our thresholds: notice we do not change our actual buy/sell conditions.
RSI(2..14) 30/70 vs RSI(2..14) 20/80
|@ES Daily 1/1/2004-1/29/2017|
|RSI(2..14) 30/70||RSI(2..14) 20/80|
|Avg Profit Per Trade:||$824.59||$850.77|
|Number of Trades||89||98|
Final Analysis & Summary
Both the 30/70 and 20/80 optimization thresholds show significant improvement in the profit per trade over the baseline, fewer trades, and higher profit factor. This suggests that our RSI optimizations are improving trade quality significantly and suggest our indicators are better synchronized to the more dominant cyclical structure of the market. While the net profits are not quite as strong, the strong increase in average profit per trade is especially appealing.
It appears we can find significant cyclical structure in the markets using simple statistical techniques. However, we did have to use some trial and error in determining the lookback to calculate our statistics over, and that may be one area for improvement.