Back to Community
Less is more: small and simple mixed strategies

Hi there,

I will share two simplified classic strategies and their respective mashup:

I. Simplified version of "Sell in May and go away" with SPY
Based on: https://www.quantopian.com/posts/time-to-sell-in-may-and-go-away

Clone Algorithm
367
Loading...
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
def initialize(context):
    pass


def handle_data(context, data):
    
    SPY = symbol('SPY')

    mm = get_datetime().month    

    if 4<mm<9:
        order_target_percent(SPY, 0.0)
    else:   
        order_target_percent(SPY, 1.0)
There was a runtime error.
7 responses

II. Simplified version of "50/200MA Crossover" with SPY
Based on: https://www.quantopian.com/posts/50-slash-200ma-crossover-strategy-spy-no-short-component

Clone Algorithm
367
Loading...
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
def initialize(context):
    pass


def handle_data(context, data):
    
    SPY = symbol('SPY')

    ma_fast = data[SPY].mavg(50)
    ma_slow = data[SPY].mavg(200)

    if ma_fast<ma_slow:
        order_target_percent(SPY, 0.0)
    else:   
        order_target_percent(SPY, 1.0)
There was a runtime error.

III. Smart SPY
Both strategies mixed: It reduces the max drawdown and improve the returns ;)

  • I think it's a good practice to work progressively with simple and effective strategies.
  • Alternatively you can short SPY instead of sell it: the returns will be better but the max drawdown will increase by 27%!!
Clone Algorithm
367
Loading...
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
def initialize(context):
    pass


def handle_data(context, data):
    
    SPY = symbol('SPY')

    mm = get_datetime().month    
    
    ma_fast = data[SPY].mavg(50)
    ma_slow = data[SPY].mavg(200)

    if 4<mm<9 or ma_fast<ma_slow:
        order_target_percent(SPY, 0.0)
    else:   
        order_target_percent(SPY, 1.0)
There was a runtime error.

IV. Smart SPY tweaked w/short component

  • NO leverage, SPY=benchmark, code easy to read
  • The rebalance frequency can be improved.
  • Does this strategy could be optimized if it works with a group of stocks?
  • How would implement the minute mode?

Enjoy!

Clone Algorithm
367
Loading...
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
def initialize(context):
    pass


def handle_data(context, data):
    
    SPY = symbol('SPY')

    mm = get_datetime().month    
    
    ma_fast = data[SPY].mavg(50)
    ma_slow = data[SPY].mavg(200)

    if 4<mm<9 and data[SPY].price>ma_fast:
        order_target_percent(SPY, -1.0)
        
    elif ma_fast>ma_slow:   
        order_target_percent(SPY, 1.0)
There was a runtime error.

Hi Martin,

thanks your interesting strategy and let us could see the powerful about quantopian backtest platform.

Thanks for sharing!

Simple strategy but look graphic data is pretty.

A minute backtest version of this strategy

Clone Algorithm
46
Loading...
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
def initialize(context):
    context.symb = symbol('SPY')
    
    set_benchmark(context.symb)

    schedule_function(
        do_daily,
        date_rules.every_day(),
        time_rules.market_open(minutes=15)
    )

def handle_data(context, data):
    pass


def do_daily(context, data):
    
    mm = get_datetime().month    
    
    ma_fast = data[context.symb].mavg(50)
    ma_slow = data[context.symb].mavg(200)

    if 4<mm<9 and data[context.symb].price>ma_fast:
        order_target_percent(context.symb, -1.0)
        
    elif ma_fast>ma_slow:   
        order_target_percent(context.symb, 1.0)
There was a runtime error.