Hello Grant,

This code builds for me. It it the example you're looking for? It's the basic batch transform example, but with the comment stripped out and added the variables.

```
R_P=1
W_L=10
def initialize(context):
context.stock = sid(16841)
context.bet_amount = 100000
context.long = 0
def handle_data(context, data):
curr_max=None
curr_min=None
if minmax(data, context.stock) is not None:
curr_max, curr_min = minmax(data, context.stock)
else:
log.info('minmax returned none')
if curr_max is not None and context.long <=0 and data[context.stock].price >= curr_max:
order_amount = calculate_order_amount(context, -1, data[context.stock].price)
log.info('Selling {n} shares of {s} at {p}'.format(n=order_amount,s=context.stock,p=data[context.stock].price))
order(context.stock, order_amount)
context.long=1
elif curr_min is not None and context.long>=0 and data[context.stock].price <= curr_min:
order_amount = calculate_order_amount(context, 1, data[context.stock].price)
log.info('Buying {n} shares of {s} at {p}'.format(n=order_amount,s=context.stock,p=data[context.stock].price))
order(context.stock, order_amount)
context.long=-1
@batch_transform(refresh_period=R_P, window_length=W_L)
def minmax(datapanel, sid):
prices_df = datapanel['price']
min_price = prices_df[sid].min()
max_price = prices_df[sid].max()
recent_price = prices_df[sid][-1]
log.info('price is {p}, max is {max}, min is {min}'.format(
p=recent_price,
max=max_price,
min=min_price)
)
if min_price is not None and max_price is not None:
return (max_price, min_price)
else:
return (None, None)
def calculate_order_amount(context, signal_val, cur_price):
current_amount = context.portfolio.positions[context.stock].amount
abs_order_amount = int(context.bet_amount / cur_price)
log.info('Current amount is: {a}.'.format(a=current_amount))
log.info('Desired amount is: {d}'.format(d=(abs_order_amount*signal_val)))
if signal_val == -1:
return (-1 * abs_order_amount) - current_amount
elif signal_val == 1:
return abs_order_amount - current_amount
else:
return 0
```