Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Context extended (dynamic property) style: Acceptable?

How about this usage of the context and the zipline.protocol.SIDData object?

def ReconcileData(context, data):  
    #  
    # Reconcile available stocks  
    #  
    for stock in data:  
        if (stock not in context.S):  
            context.S[stock] = data[stock]  
    for stock in context.S:  
        if (stock not in data):  
            del context.S[stock]  

So that we can use this syntax:

    context.S[stock].PivotPoint = pp  

as in:

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
def HandleEntry(context, data):  
    eligible = []  
    for stock in context.S:  
        pp = (data[stock].close_price + data[stock].high + data[stock].low) / 3.0  
        if ('PivotPoint' in context.S[stock]):  
            if (data[stock].close_price > context.S[stock].PivotPoint * 1.01):  
                eligible.append(stock)  
        #  
        # Expando  
        #  
        context.S[stock].PivotPoint = pp

    eligibleCount = float(len(eligible))  
    for stock in eligible:  
        if (context.portfolio.positions[stock].amount == 0.0):  
            order_target_percent(stock, 1.0 / eligibleCount)  
            print(">> Entry {0:>4} {1:>7.2f}".format(stock.symbol, context.S[stock].PivotPoint))  
1 response

Because we can't add the iter or contains to any classes we build we have to use what's already in the object tree.

This works also, which may reduce the storage burden:

    for stock in data:  
        if (stock not in context.S):  
            context.S[stock] = zipline.protocol.SIDData(stock)