Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Found a strange result

I’ve been using the debugger in the IDE to dig down into what my algorithm is actually doing and found some strange results. The general form of my filter is like this (where I substitute values for x and y):

def before_trading_start(context):  
    fundamental_df = get_fundamentals(  
        query(  
            fundamentals.operation_ratios.roa,  
            fundamentals.valuation_ratios.pe_ratio,  
            fundamentals.valuation.market_cap  
        )  
        .filter(fundamentals.valuation.market_cap > x)  
        .filter(fundamentals.valuation_ratios.pe_ratio > y)  
        .filter(fundamentals.operation_ratios.roa > 0)  
        .order_by(fundamentals.valuation_ratios.pe_ratio)  
        .limit(50)  
    )  
    context.fundamental_df = fundamental_df  
    update_universe(context.fundamental_df.columns.values)  

I looked at the dataframe returned from three separate queries using different filter values and found something weird.

  1. P/E > 20, market cap > 50000000, February 2002

Of the fifty companies returned the ROA values were as follows:
5 had 2.04%
7 had 0.95%
13 had 7.062%
25 had 1.87%

  1. P/E > 5, market cap > 50000000, February 2002

Of the fifty companies returned the ROA values were as follows:
5 had 2.09%
7 had 3.10%
13 had 0.29%
25 had 25.56%

  1. P/E > 5, any market cap, October 2014

Of the fifty companies returned the ROA values were as follows:
5 had 3.61%
7 had 0.14%
13 had 0.74%
25 had 1.86%

Each query returns this pattern of 5,7,13,25 ROA’s that are the same. The same pattern is also found in the returned P/E and Market cap metrics (with different numbers).

I guess the problem is this could have implications for ranking stocks.

I went and used an online stock scanner and didn't see anything like this pattern (for stocks currently).

Anybody else found this when ranking stocks by fundamental metrics?

Edit:

I am using context.fundamental_df.irow(z) (where z is 0 = ROA, 1 = P/E and 2 = Market cap) in the debugger console to get at the raw values. Could this possibly be introducing some type of error?

3 responses

Hi Kane,
I was able to reproduce this result. I suspect it is an issue with the debugger because when I printed out the values to the log, they didn't match the debugger's suspicious pattern.

Thanks,
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.

Sounds pretty similar to this bug: https://www.quantopian.com/posts/debugger-problem