Fawce,
The full backtest (01/03/2012 to 01/06/2012) actually completes (slowly) with:
def initialize(context):
context.stock = sid(16841)
def handle_data(context, data):
avg = get_avg(data,context.stock)
event_time = data[context.stock].datetime
log.debug(event_time)
log.debug(avg)
@batch_transform(refresh_period=0, window_length=1)
def get_avg(datapanel,sid):
prices = datapanel['price']
avg = prices[sid].mean()
return avg
A sample of the log output:
2012-01-03handle_data:8DEBUG2012-01-03 20:59:00+00:00
2012-01-03handle_data:9DEBUGNone
2012-01-03handle_data:8DEBUG2012-01-03 21:00:00+00:00
2012-01-03handle_data:9DEBUGNone
2012-01-04handle_data:8DEBUG2012-01-04 14:31:00+00:00
2012-01-04handle_data:9DEBUG177.443721228
2012-01-04handle_data:8DEBUG2012-01-04 14:32:00+00:00
2012-01-04handle_data:9DEBUG177.454245524
2012-01-04handle_data:8DEBUG2012-01-04 14:33:00+00:00
2012-01-04handle_data:9DEBUG177.461867008
2012-01-04handle_data:8DEBUG2012-01-04 14:34:00+00:00
2012-01-04handle_data:9DEBUG177.470076726
Note that avg changes every minute. So, what's happening? Is it an N-tick moving price average that gets updated every minute? If so, what is N? Is N a fixed value regardless of the datetime?
See https://www.quantopian.com/posts/mavg-days-transform-details for more of the confusion around computing moving averages for minutely trading.