Back to Community
RSI Strategy

RSI Strategy

Clone Algorithm
321
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: 55e04919ae1e450d83e5356c
There was a runtime error.
9 responses

Hey, nice work. Two suggestions:
1. Try mean-reversion strategies for other equities than SPY? The reason for this is that SPY in particular is somewhat slow-moving. Maybe try an equity with a bit more volatility, and you could see much greater returns.
2. Are you sure that 10/200 are the best long/short windows? I suggest you try something like this to find the best.

Hey John,

I will try mean reversion strategy and let you know.Thanks for suggestions.

Sorry, I actually meant that you should try your RSI strategy with equities other than SPY. But mean-reversion is good too. :-) The results should be similar, I think.

no problem.

Hello I'm new.
I'm looking to run your strategy but i got an error : Runtime exception: NameError: name 'ta' is not defined LINE 8
Where I'mwrong?
Thanks

Hello,
I have the same problem.

That algorithm was written on the old version of Quantopian, which is why it won't run as is. Here it is compatible with Qver2

Clone Algorithm
27
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: 59848a781b35b9566f7f6b24
There was a runtime error.

You can see from 2012 it has 1+ beta and no alpha -- it simply goes long SPY and uses a little bit of leverage to outpace it until Oct 20, 2014 when it makes a mistake and shorts SPY while SPY is still bullish. Out of sample, it performed well -- it went to cash to avoid 2015 and 2016 drawdown periods, which is good -- most algorithms fail out of sample -- but it also doesn't make any gains there either.

I wouldn't recommend trading this algo, but its signal might be useful to determine how much market exposure or risk to allow another algorithm to take, or to dynamically adjust its parameters. (IE, if algorithm performs well in a bull market with one set of settings, and performs well in uncertain markets with another set of settings.) Then again, this algorithm buys and sells so infrequently it's hard to draw any strong statistical conclusions.

Viridian Hawk,

Almost the same, but long only plus bond:

import talib 

def initialize(context):  
    schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_open(minutes = 1))

def my_rebalance(context, data):  
    # -----------------------------------------  
    stock, bond = symbol('SPY'), symbol('IEF')  
    ma_f, ma_s, rst_period, LB = 10, 200, 3, 10  
    # -----------------------------------------  
    if get_open_orders(): return  
    price    = data.current(stock,'price')  
    mavg_f   = data.history(stock, 'price', ma_f,'1d').mean()  
    mavg_s   = data.history(stock, 'price', ma_s,'1d').mean()  
    hist_rsi = data.history(stock, 'price', rst_period + 1,'1d')  
    rsi      = talib.RSI(hist_rsi, rst_period)[-1]  
    stock_position = context.portfolio.positions[stock].amount

    if all(data.can_trade([stock, bond])):  
        if price > mavg_s and rsi < LB and stock_position == 0:  
            order_target_percent(stock, 1.0)  
            order_target(bond, 0)  
        elif price > mavg_f and (mavg_f < mavg_s*1.015) and stock_position > 0:  
            order_target(stock, 0)  
            order_target_percent(bond, 1.0) 

    record(leverage = context.account.leverage)  
'''
Total Returns  
393.1%  
Benchmark Returns  
268.2%  
Alpha  
0.09  
Beta  
0.25  
Sharpe  
1.01  
Sortino  
1.44  
Volatility  
0.11  
Max Drawdown  
-17.11%

100000  
START  
11/01/2002  
END  
08/03/2017

'''