You should probably organize your layout w/ something along these lines:
def initialize(context):
# choose the top two percentile of DollarValue rankings
set_universe(DollarValueUniverse(98.0, 99.0))
# construct a new batch transform, tuck it into the context
# call the function my_transform every two days, keeping 7 days of history in the data panel
context.a_batch_transform = BatchTransform(func=my_transform, refresh_period=2, delta=timedelta(days=7))
def handle_data(data, context):
# update the transform with the current data events
transform_results = context.a_batch_transform.handle_data(data)
# place orders, rebalance portfolio, etc.
order(transform_results.buys[0], 10)
def my_transform(data_panel):
prices_dataframe = data_panel['price']
# do work on prices...
# return the data your algorithm will need to make buy/sell choices
return transform_results
Obviously this won't run any result, but I hope it generalizes some "flow of concept" :P