How would i substitute Q500US in this code?
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import AverageDollarVolume
from quantopian.pipeline.filters.morningstar import Q500US
attach_pipeline
import re
import datetime as dt # Surprising that datetime doesn't have timezone
import pandas as pd
from pytz import timezone
from zipline.utils import tradingcalendar
def initialize(context):
schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_open(hours=1))
attach_pipeline(make_pipeline(), 'my_pipeline')
context.aapl = sid(24)
context.spy = sid(8554)
context.googl = sid(46631)
context.agn = sid(205)
context.infn = sid(33979)
def handle_data(context,data):
stocks = symbols('AAPL','GOOG','AGN','INFN','prx','m', 'a','aa','aac','aan','aat', 'aap','aav','ab','abb','l','lad','ladr')
for stock in stocks:
if get_open_orders(stock): return
hist= data.history(stock, 'price', 30, '1d')
if hist[-1] < hist[0:-2].min() and data.can_trade(stock) and context.account.leverage<=2.8:
order_target_percent(stock, 0.5)
elif hist[-1] >= hist[0:-2].max() and data.can_trade(stock):
order_target(stock, 0)
record(leverage=context.account.leverage)
def make_pipeline():
"""
A function to create our dynamic stock selector (pipeline). Documentation on
pipeline can be found here: https://www.quantopian.com/help#pipeline-title
"""
# Base universe set to the Q500US
base_universe = Q500US()
# Factor of yesterday's close price.
yesterday_close = USEquityPricing.close.latest
pipe = Pipeline(
screen = base_universe,
columns = {
'close': yesterday_close,
}
)
return pipe
def before_trading_start(context, data):
results = pipeline_output('my_pipeline')
print results.head(5)
"""
Called every day before market open.
"""
#I MAY NEED THIS context.output = pipeline_output('my_pipeline')
# These are the securities that we are interested in trading each day.
#COULD NEED THIS context.security_list = context.output.index
def my_assign_weights(context, data):
"""
Assign weights to securities that we want to order.
"""
pass
def my_rebalance(context,data):
"""
Execute orders according to our schedule_function() timing.
"""
pass
def my_record_vars(context, data):
"""
Plot variables at the end of each day.
"""
pass
"""
Called once at the start of the algorithm.
"""
# Rebalance every day, 1 hour after market open.
schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_open(hours=1))
# Record tracking variables at the end of each day.
schedule_function(my_record_vars, date_rules.every_day(), time_rules.market_close())
# Create our dynamic stock selector.
# attach_pipeline(make_pipeline[my_pipeline] )