The S&P 500 index is weighted by float-adjusted market capitalization.
So if you take top 10 by market capitalization from Q500US they should in most cases be in top 10 holdings in S&P 500 index.
Try something like this:
from quantopian.pipeline import Pipeline, factors, filters, classifiers
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline.data import Fundamentals
def initialize(context):
schedule_function(trade, date_rules.every_day(), time_rules.market_open(minutes = 65))
market_cap = Fundamentals.market_cap.latest
top_market_cap = market_cap.top(10, mask = filters.Q500US())
attach_pipeline(Pipeline(columns = {'market_cap': market_cap}, screen = top_market_cap), 'stock_set')
def trade(context, data):
output = pipeline_output('stock_set')
stocks = output.sort_values('market_cap', ascending = False).head(10).index
print stocks
and compare to morningstar data