Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Does the range_specifier in get_fundamentals() in research platform work?

I get NaN. I was expecting the values to be populated per the document.

fund_df = get_fundamentals(query(fundamentals.valuation_ratios.pe_ratio)  
                             .filter(fundamentals.valuation.market_cap > 10e9)  
                             .filter(fundamentals.valuation_ratios.pe_ratio > 5)  
                             .order_by(fundamentals.valuation.market_cap)  
                             .limit(4),  
                            today, '5y')

# OK, let's check out what we get back.  
# When we provide a query and a date, we get back the same type of response  
# as in the IDE: a dataframe with securities as columns and each requested  
# metric as rows.

fund_df['pe_ratio']  
1 response

Hi Saravanan,

The reason for the NaNs is that when filtering and ordering on a time series, the returned criteria can be totally different at totally different points. At the point at which they don't match the filter criteria, a NaN is returned.

For example, in this query it looks like you want the 4 lowest market cap stocks, that are also capitalized above $10B and have a P/E greater than 5. As of 9-6-2011, those stocks were BF_A, CPB, CLR and YNDX. However, a year later, the stocks that match the criteria were CAG, HOG, HNP and CHKP, which is a completely different set of companies!

As a result, the first batch from 2011 gets filled in with NaNs in 2012, to indicate that they no longer meet the criteria set by the filter and order_by statements. This is by design - the NaNs make it very clear when a stock passed your filter, and when it didn't, making it easy to tell what companies meet your criteria at any given point in time.

However, the downside of this approach is that the data returned is often pretty sparse, as it was with this query. To get a fully populated DataFrame, you could get the sids of the companies in the dataframe from your original query, and then do

fund_panel = get_fundamentals(query( fundamentals.valuation_ratios.pe_ratio )  
    .filter(fundamentals.company_reference.sid.in_((my_sids))),  
     today, '5y')  

Hope this helps!

Abhijeet

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.