I think there may be a refresh_period bug in batch_transform, as shown in the code below.
# When run in daily mode from 1/7/2008 to 1/15/2008, this code
# shows a problem with batch_transform.
# The refresh_period argument to @batch_transform is set to 2,
# so the logged price window should update every other day.
# But if SHOW_BUG is True, the window updates every day:
# 2008-01-07 PRINT No prices
# 2008-01-08 PRINT No prices
# 2008-01-09 PRINT [ 177.58 171.23 179.5 ]
# 2008-01-10 PRINT [ 171.23 179.5 178.02]
# 2008-01-11 PRINT [ 179.5 178.02 172.4 ]
# 2008-01-14 PRINT [ 178.02 172.4 178.738]
# 2008-01-15 PRINT [ 172.4 178.738 169. ]
# If SHOW_BUG is False, the window updates every other day as
# it should (except for the first day):
# 2008-01-07 PRINT No prices
# 2008-01-08 PRINT No prices
# 2008-01-09 PRINT [ 177.58 171.23 179.5 ]
# 2008-01-10 PRINT [ 171.23 179.5 178.02]
# 2008-01-11 PRINT [ 171.23 179.5 178.02]
# 2008-01-14 PRINT [ 178.02 172.4 178.738]
# 2008-01-15 PRINT [ 178.02 172.4 178.738]
SHOW_BUG = True
# Initialize context to pass to other methods.
def initialize(context):
context.stock = sid(24)
# Handle trade data events.
def handle_data(context, data):
# To show the bug, foo can be any property of
# data[context.stock], e.g. price, volume, etc.
foo = data[context.stock].volume if SHOW_BUG else 0
prices = transform(data, foo)
print prices if prices is not None else 'No prices'
@batch_transform(window_length=3, refresh_period=2)
def transform(datapanel, foo):
return datapanel['price'].as_matrix().flatten()