Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Algo not backtesting correctly

My algo is not backtesting correctly. It is not pulling in the cumulative returns. Rick constraints are being identified, but that's about it. The algo is supposed to go long on stocks whose price is 5% under the 5day EMA. Any help would be greatly appreciated.

1 response

Try to compute target weights this way:

def compute_target_weights(context, data):  
    weights = {}  
    if context.close_vs_EMA5:  
        weight = 1.0 / len(context.close_vs_EMA5)  
    else:  
        return weights

    for security in context.portfolio.positions:  
        if security not in context.close_vs_EMA5 and data.can_trade(security):  
            weights[security] = 0

    for security in context.close_vs_EMA5:  
        weights[security] = weight

    return weights