Hey guys,
I'm trying to set my universe as the S&P500. What's the best way to do this? Currently I'm doing something like this:
def before_trading_start(context, data):
today = get_datetime().date()
sp_500 = get_fundamentals(
query(fundamentals.valuation.market_cap,
fundamentals.company_reference.primary_exchange_id)
.filter(fundamentals.valuation.market_cap > 4e9)
.filter(fundamentals.company_reference.country_id == "USA")
.filter(or_(fundamentals.company_reference.primary_exchange_id == "NAS",
fundamentals.company_reference.primary_exchange_id == "NYS"))
.order_by(fundamentals.valuation.market_cap.desc())
.limit(500),
today)
sids = sp_500.columns.values
context.stocks = [s.sid for s in sids]
However this only returns about 100 something stocks (varies with each day / month). To my understanding, this is because of the fixed value for the market_cap at 4e9. That value changes with the time so I can't have a fixed value. That being said, what's the best way to get the S&P500 stocks over time?
Thanks for the help,
Thomas