Back to Community
ETF Strategy

This strategy is an equity and bond momentum algorithm. I use 3x leveraged equity ETF (SSO) and the 20 year US Treasury ETF (TLT).
A special thanks to Kory Hoang for this algorithm template.

Can anyone increase the sharpe ratio?

2 responses

[enter link description here][1]Sharpe at 1.12 now with 29% dd for 950% total returns. Can someone optimise further? It seems 2015 was not a great year for the algorithm.


Clone Algorithm
Total Returns
Max Drawdown
Benchmark Returns
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.quarter_flag = False
    context.asset1 = symbol('SSO') # SPY leveragec 3x
    context.asset2 = symbol('TLT') # US Treasuries
    context.Buy = 0
    context.Current = 0
    context.BuyAlert = False
    set_slippage(slippage.FixedSlippage(spread=0.01)) # average $0.01 bid/ask spread per share
    set_commission(commission.PerShare(cost=0.005, min_trade_cost=0.00)) # $0.005/share, $1 minimum 
    schedule_function(end_of_month, date_rule=date_rules.month_end())
    schedule_function(rebalance, date_rules.month_start(), time_rules.market_close(minutes=30))

def rebalance(context, data):
    if context.BuyAlert:
        if context.Current != 0:
            order_target_percent(context.Current,  0)
        order_target_percent(context.Buy,  1)
        context.Current = context.Buy
        context.BuyAlert = False

def end_of_month(context, data):
    if get_datetime().month % 1 == 0: 
        n = 110
        context.quarter_flag = True
        maxPercent = 0
        asset1_prices = data.history(context.asset1, "price", n, "1d")
        asset1_PercentChange = (asset1_prices[-1] - asset1_prices[-110]) / asset1_prices[-1]
        if asset1_PercentChange > maxPercent:
            context.Buy = context.asset1
            maxPercent = asset1_PercentChange
        asset2_prices = data.history(context.asset2, "price", n, "1d")
        asset2_PercentChange = (asset2_prices[-1] - asset2_prices[-110]) / asset2_prices[-1]
        if asset2_PercentChange > maxPercent:
            context.Buy = context.asset2
            maxPercent = asset2_PercentChange
        if context.Buy != context.Current:
            context.BuyAlert = True

def before_trading_start(context, data):
    if context.quarter_flag:
        context.quarter_flag = False
There was a runtime error.

Hello - whenever I see someone posting a series of tweaks like this, I worry that you're overfitting to past results.

Do you have a strategy to prevent overfitting?


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.