Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Filtering out instances of multiple securities using get_fundamentals() - MSFT example

Im writing my first full algorithm, replicating the Magic Formula.

Im running into an issue with get_fundamentals() where there are two securities for Microsoft, MSFT and MSFTV. I understand the economics of why there are two securities, but I can't find a good way to systematically filter out these kind of situations from the get_fundamentals() method.

In the example below, Im attempting to always have 5 positions but starting in early 2003 there are consistently 6 positions and one of them is MSFTV.

Does anyone know a good way of dealing with these instances? The goal is to update my universe everyday with a set of unique securities and only have 5 of them into portfolio.

3 responses

Hi Colin,

I went to my bag of usual tricks on this and came up empty in the case of MSFTV. Usually, something in share_class_reference or company_reference can help distinguish these types of share classes inside the query.

I did notice that the symbol and primary_symbol field returned by get_fundamentals was MSFT for MSFTV. So you could access the symbol attribute of the Equity object in the dataframe returned by get_fundamentals and compare it to the symbol field, after you've run the query.

Hope that makes sense,
Josh

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.

There's also the flag is_primary_share

Josh & Simon,

Thanks for replies - had some time to work on this issue today and Josh's suggestion of using symbol and primary_symbol was spot on.

def checkIfPrimaryShares(context, fundamentals_df):  
    for stock in context.stocks:  
        if stock.symbol != fundamentals_df[stock].primary_symbol:  
            log.info("%s: non-primary shares, removing from context.stocks" %(stock.symbol))  
            context.stocks.remove(stock)