Back to Community
Sentiment Mean Reversion Leverage Adjustment

Hi All,

Could anyone help me figure out why my algorithm won't use the full allotted leverage of 1? Right now, it only goes up to about 0.3 when it should go up to anywhere between 0.8 to 1.0. I also think this might the reason why the returns are lower than expected.

Thanks,

Rohit

Clone Algorithm
2
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: 597bb84ff435ba4f32e8e4f6
There was a runtime error.
3 responses

Do the zscore screening first and then apply the weights, .6 and -.4 using the len of those that made it through.

Would that have to be done through pipeline as well? Or could I just write another function that handles the z-score screening after I assign longs and shorts based on sentiment and then finally order my securities?

Both ok. I pictured a route like this, guard against margin though, at a minimum, record cash.

def rebalance(context, data):  
    #long_weight, short_weight = compute_weights(context, data)  
    context.long_secs  = context.output[context.output['longs']].index  
    context.short_secs = context.output[context.output['shorts']].index  
    longs = {}  
    shrts = {}

    # zscore screen, both at same time  
    for stock in context.long_secs.union(context.short_secs):  
        zscore = calculate_zscore(stock ,data)  
        if   zscore < -1.65:  
            # The value of zscore here so far is unused, just a way of storing these in dict instead of list  
            longs[stock] = zscore  
            log.info(' long {}: {}'.format(stock.symbol, '%.4f' % zscore)) # to 4 decimal places  
        elif zscore > 1.65:  
            shrts[stock] = zscore  
            log.info('short {}: {}'.format(stock.symbol, '%.4f' % zscore)) # to 4 decimal places

    # Place orders for longs  
    for stock in longs:  
        order_target_percent(stock, .6 / len(longs))  
        log.info(' long ' + stock.symbol)

    # Place orders for shorts  
    for stock in shrts:  
        order_target_percent(stock, -.4 / len(shrts))  
        log.info('short ' + stock.symbol)