Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Need help with Connors RSI Algorithm

Hello! I'm working on an algorithm to trade based on the Larry Connors RSI strategy. Based on the research I've read, this strategy should perform very well, and yet my results are lackluster. I'm hoping it's a typo or small problem with my code. I'm least confident about the compute_target_weights function.

Entry signal:
Price > SMA(200)
RSI(2) <= 5

Exit signal:
Price > SMA(5)

Notes:
1. Connors suggests rebalancing at market close, but I'm unable to figure out how to calculate RSI at market close using Pipeline, so instead I have the algorithm rebalancing every day at market open.
2. Eventually I want to run this strategy long/short, but I want to make sure it's working properly long-only to start.
3. The backtest runs really slow! Is there some obvious optimization or refactor I can do to speed it up?

(Related post)

2 responses

A few things...

First, use the '&' operand when making filters from factors. The word 'and' doesn't operate as expected. That will get your algorithm working as expected. The results can be improved by using more typical values for RSI window length and RSI min value of 15 days and 30 respectively (original code has 2 and 5). Not to imply those are optimal by any measure just that the results are better. Finally, to improve the speed stay away from loops. Most statements can be implemented in a single line without a loop using pandas methods. The attached backtest shows these changes.

that's wonderful Dan, thanks for the quick response!