Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
batch transform, minute data?

Hello,

Would someone be so kind to post an example of the batch transform that runs on minute data? I just can't seem to sort out what I might be doing wrong in the code below.

Thanks,

Grant


import numpy as np

# globals for get_data batch transform decorator  
R_P = 1  # refresh period in days  
W_L = 3 # window length in days

def initialize(context):  
    context.stocks = [sid(24),sid(8229),sid(8554),sid(5061),sid(8459)]  
def handle_data(context, data):  
    # get data (select prices, volume, etc. in batch transform get_data)  
    d = get_data(data, context.stocks)  
    if d is None:  
        return  
    current_prices = np.zeros(len(context.stocks))  
    for i,stock in enumerate(context.stocks):  
        current_prices[i] = data[stock].price  
    timestamp = data[context.stocks[0]].datetime  
    print ' ----------------------------'  
    print timestamp  
    print ' ----------------------------'  
    print ' Securities'  
    print context.stocks  
    print ' Current prices'  
    print current_prices  
    print ' Trailing price window'  
    print d

@batch_transform(refresh_period=R_P, window_length=W_L) # set globals R_P & W_L above  
def get_data(datapanel,sids):  
    return datapanel['price'].as_matrix(sids)