Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
US500 rank universe question

Hi Pros,

Just working on a pipeline screener which needs to rank several metrics.

As my universe is US500, im noticed that results shows rank values beyond of 500. I mean, its seems that rank function is based on a total universe with more than 8K of stocks. It is correct?

I was exepcting values <= 500 since this is the number of stocks of the filter universe.

Enclosed a simple rank pipeline where you can see rank values of 500 highest.

I know tha this is a very basic question, but as a begineer don't understand why.

Thanks for any help.

2 responses

The pipeline definition first creates the factor named 'closerank' as shown below

    closerank = USEquityPricing.close.latest.rank()

Since there are no qualifiers, filters, or masks provided, the rank method will use the entire universe (~8000) of stocks. Since you want to apply the ranking only to the smaller Q500US, defined as 'universe', then use the mask parameter. Something like this

    closerank = USEquityPricing.close.latest.rank(mask=universe)

That will limit the ranking to just those stocks which meet the mask criteria. In this case only those stocks in the Q500US. Adding the screen=universe parameter to the final pipeline definition only limits the stocks which the pipeline will output. This is after the rank factor has been calculated.

Good luck.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thanks! Dan, clear!