I am trying to see the stocks that I am getting buy and sell signals using a simple VWAP comparison. However, when I try to build my algorithm, it says "There was a runtime error. See the more detailed error below", then gives no details. Does anyone know what's going on?
def initialize(context):
set_universe(universe.DollarVolumeUniverse(floor_percentile=97.0, ceiling_percentile=99.0))
context.stocks = []
context.max_notional = 1000000.0
context.min_notional = -1000000.0
context.index_position = 0
def handle_data(context, data):
# Implement your algorithm logic here.
context.stocks = [sid for sid in data]
#buys = set()
#sells = set()
for stock in context.stocks:
# S&P 500 ETF is sid(8554) - ticker is 'SPY'
if vwap_buy(stock, data) == 1:
# Buy stock, Sell S&P 500
#buys.add(stock)
log.info("Found BUY signal for " + str(stock))
elif vwap_buy(stock, data) == -1:
# Sell stock, Buy S$P 500
#sells.add(stock)
log.info("Found SELL signal for " + str(stock))
elif vwap_buy(stock, data) == 0:
# No Position
log.info("No signal for " + str(stock))
def vwap_buy(stock, data):
if stock in data:
if data[stock].returns() > data[stock].vwap(5):
if data[stock].returns() > data[stock].vwap(10):
# Sell Signal
return -1
elif data[stock].returns() < data[stock].vwap(5):
if data[stock].returns() < data[stock].vwap(10):
# Buy Signal
return 1
else:
# No Position Signal
return 0