Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pipeline problem

I used filter to see which 500 companies are in the "largest 500 companies in terms of market cap". I got the result as True or False. But how can i arrange those companies in descending order?

def make_pipeline():  
    # Gets the latest market cap.  
    mkt_cap = morningstar.valuation.market_cap.latest  
    # Filter for the top 500 securities by market cap.  
    top_mkt_cap = mkt_cap.top(500)  
    return Pipeline(  
        columns={  
            'top 500': top_mkt_cap  
        }  
    )  
result = run_pipeline(make_pipeline(), '2016-01-01', '2016-01-01')  
result.head()  
3 responses

This should get you started:

That was helpful, thank you JS.
Here simplified, using screen ...

from quantopian.pipeline  import Pipeline  
from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline.data import morningstar

def initialize(context):  
    pipe = Pipeline()  
    attach_pipeline(pipe, 'pipeline')  
    mkt_cap = morningstar.valuation.market_cap.latest  
    pipe.add(mkt_cap, 'mkt_cap')  
    pipe.set_screen(mkt_cap.top(500))

def before_trading_start(context, data):  
    result = pipeline_output('pipeline')  
    print result.sort_values('mkt_cap', ascending=False).head()  

Much simpler, I can usually get the job done but there's almost always a more elegant way to write the code, thanks Blue.