Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pipeline Mask = MarketCap Top 500?

Hi,

I'm relatively new to python and new to Quantopian.

I've been actively going through the learning modules and searching the community while developing a notebook to piece together my first algo over the next few weeks.

While going through the Pipeline lessons, I put together a simple EMA cross over but am still roughing out my notebook and spot testing along the way.

At the moment, I'm stuck on how to setup a preliminary pipeline mask to only analyse the top 500 securities by market cap.

I've looked at the doc. help section but it only shows:

All classes and functions listed here are importable from quantopian.pipeline.factors.morningstar.

class MarketCap  
Factor producing the most recently known market cap for each asset.  

Attached is my current notebook that seems to attach marketcap to each security but the top(#) only filters the top # securities in it's current order and not based on market cap.

Any help is really appreciated,

6 responses

You are doing it correctly. You've filtered to only the top 500 securities by market capitalization (by setting the mask = mktcap_500) and then filtered further by setting the screen to EMA_uptrend. The result is 145 securities from the largest 500 market cap that have EMA_uptrend equal to true.

 mktcap_500 = mktcap.top(500)  

That will return true for the top 500 securities with the largest market capitalization. The '.top' method does a 'sort_values' and a 'head' functionality behind the scenes. See the attached notebook. I added a couple of columns to your pipe. You can see that the filter returns true for the top 500. I sorted by mktcap and used '.head(501) so you can see the cutoff at 501.

Hi Jon,

To create a Filter for the top 500 securities by market cap, I would recommend using the morningstar Dataset. It would look something like this:

# Import the morningstar dataset.  
from quantopian.pipeline.data import morningstar

# 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)  

Does this help?

The MarketCap filter should work too, it's just a matter of preference whether you want to use it, or the factor generated by .latest.

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.

@Dan Whitnable : Thanks for taking the time to build out a quick example to confirm the ordering!

@Jamie McCorriston : Appreciate the alternative approach of using Morningstar, the implementation example will definitely come in handy when I layer in some fundamental factors as additional filters.

how would i go about making the filter say marketcap is more than 500M?

"setting market cap" mktcap = morningstar.valuation.market_cap.latest
"making sure market cap is above 500 million"
mc_above_500m = (mktcap > 500000)

would something like that work?

@ John R

Your filter sort of works but you need some more zeros.

mc_above_500m = (mktcap > 500000000)