Hi, I am a beginner at Python and programming in general so this may be a dumb question.
I am trying to understand how to add custom fields to batch transform. The example in the help section shows how to accumulate over_vwap, the custom field.
I tried testing the example on my end and received this error, "KeyError: no item named over_vwap".
My guess is there is a line of code missing that should add over_vwap to the dataframe, but I can't think of the function.
def initialize(context):
set_universe(universe.DollarVolumeUniverse(99.9, 100.0))
def handle_data(context, data):
for stock in data:
if data[stock].price > data[stock].vwap(30):
data[stock]['over_vwap'] = 1
else:
data[stock]['over_vwap'] = 0
print_signals(data)
@batch_transform(window_length=5)
def print_signals(datapanel):
signal = datapanel['over_vwap']
log.info('\n%s' % signal)