Looking to use the universe as a filter to get SP500 stocks only in the pipeline. 2 questions:
- will the pipeline refresh - daily / before trading - assume yes
- is refreshing the universe - every time make_pipeline will work:
def make_pipeline():
"""
This will return the top 500 US stocks by market cap, dynically updated.
"""
# Base universe set to the SP500
universe_sp500 = Universe(get_universe_sp500())
yesterday_close = USEquityPricing.close.latest
pipe = Pipeline(
screen = universe_sp500,
columns = {
'close': yesterday_close
}
)
return pipe
#The universe is updated on the fly:
def get_universe_sp500()
univese_sp500 = "us-sp500-snapshot"
start_date = get_crurrent_datetime() - timedelta(days=(1))
prices = get_prices("usstock-1d", start_date=start_date, fields="Close")
closes = prices.loc["Close"]
df_sp500 = get_sharadar_sp500_reindexed_like(closes)
# get the stocks that are in SP500 now.
sp500_sids = df_sp500[(df_sp500['Date']==start_date)]['Sid']
download_master_file("sp500_secs.csv", sides=sp500_sids, sec_types="STK", fields="Close")
create_universe(univese_sp500, infilepath_or_buffer="sp500_secs.csv")
return univese_sp500