from sqlalchemy import or_
fundamentals = init_fundamentals()
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),
'2009-01-02') # so we're not biased by survivorship, use the first date in the range
print len(sp_500.columns)
sp_500
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),
'2015-04-01') # so we're not biased by survivorship, use the first date in the range
print len(sp_500.columns)
sp_500