def initialize(context):
set_universe(universe.DollarVolumeUniverse(floor_percentile=90.0, ceiling_percentile=100.0))
# Will be called on every trade event for the securities you specify.
def handle_data(context, data):
for stock, event in data.items():
vwap=stock.vwap(1)
price=data[stock].mavg(1)
notional = context.portfolio.positions[stock].amount * price
if vwap is None:
return
if price < vwap * 0.995 and notional > context.min_notional:
order(stock,-100)
elif price > vwap * 1.005 and notional < context.max_notional:
order(stock,+100)
i seem to not be able to get this algorithm to work, i know i must be missing something. I am trying to learn the set universe stuff, but i really dont get it i guess.