Hello. I am trying to develop a pipeline for my golden cross algo that takes the most profitable securities from the q500. Is there anyone that could possibly lend me a hand wit that?
def initialize(context):
context.ETFs = [sid(26807), # gld
sid(19920), # qqq
sid(23921), # tlt
sid(25902), # VCR (Vanguard Consumer Discretionary ETF)
sid(25906), # VHT (Vanguard Health Care ETF)
sid(25905)] # VGT (Vanguard Information Technology ETF)
context.QUICK = 50
context.SLOW = 200
#parameters for short and long moving average
context.fixed_frac = 1.0/len(context.ETFs)
def handle_data(context, data):
closes = data.history(context.ETFs, 'price', 200, '1d')
#gets price data for our etfs
for etf in context.ETFs:
faster = closes[etf].iloc[-context.FASTER:].mean()
quick = closes[etf].iloc[-context.QUICK:].mean()
slow = closes[etf].iloc[-context.SLOW:].mean()
record(short_mavg = quick, long_mavg = slow)
if quick>slow:
if not get_open_orders(etf):
order_target_percent(etf, -context.fixed_frac)
else:
if not get_open_orders(etf):
order_target_percent(etf, context.fixed_frac)