I'd posted some example code: [https://www.quantopian.com/posts/access-elements-returned-from-batch-transform].[1] It no longer runs...any idea what's going on? Seems that it may be related to the change to the batch transform.
--Grant
import numpy as np
# globals for get_data batch transform decorator
R_P = 1 # refresh period in days
W_L = 1 # window length in days
def initialize(context):
context.stocks = []
bottom = 98
range = 0.1
log.info("universe is {b} to {t}".format(b=bottom, t=bottom+range))
set_universe(universe.DollarVolumeUniverse(bottom, bottom+range))
def handle_data(context, data):
context.stocks = [sid for sid in 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)