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

Hello,

I'm trying to develop a value algorithm. I get really strange values for fundamentals.
Here is my request:

  fundamental_df = get_fundamentals(  
        query(  
            # To add a metric. Start by typing "fundamentals."  
            fundamentals.operation_ratios.roic,  
            fundamentals.valuation_ratios.pb_ratio  
        )  
             # No Financials (103) and Real Estate (104) Stocks, no ADR or PINK, only USA  
        .filter(fundamentals.asset_classification.morningstar_sector_code != 103)  
        .filter(fundamentals.company_reference.country_id == "USA")  
        .filter(fundamentals.asset_classification.morningstar_sector_code != 104)  
        .filter(fundamentals.share_class_reference.is_depositary_receipt == False)  
        .filter(fundamentals.share_class_reference.is_primary_share == True)  
        .filter(fundamentals.company_reference.primary_exchange_id != "OTCPK")  
         # Check for data sanity (i,e. avoid division by zero)  
        .filter(fundamentals.valuation.market_cap > 10000000)  
        .filter(fundamentals.valuation.shares_outstanding > 0)  
        .filter(fundamentals.balance_sheet.invested_capital > 0)  
        .filter(fundamentals.balance_sheet.common_stock_equity>0)  
        .filter(fundamentals.balance_sheet.invested_capital != fundamentals.balance_sheet.cash_and_cash_equivalents)  
        .order_by(fundamentals.valuation_ratios.pb_ratio.asc())  
       .limit(num_stocks)  
    )  

With the debugger, I display the data:

fundamental_df: DataFrame
0_Security(20281 [SBAC]): Series
0_roic: -0.014446
1_pb_ratio: 0.0772
1_Security(22720 [GEN]): Series
0_roic: 0.0772
1_pb_ratio: -0.014446
2_Security(20160 [TWTC]): Series
0_roic: -0.014446
1_pb_ratio: 0.0772
3_Security(23798 [NPO]): Series
0_roic: 0.0772
1_pb_ratio: -0.014446
4_Security(15230 [TIE]): Series

This looks really odd. See the alternating values. It is not ordered by the criteria. Looks like corrupted memory, or I overlooked something.
Regards

2 responses

Your instincts on memory funkiness are correct -- I suspect it is another instance of this bug in the debugger: https://www.quantopian.com/posts/debugger-problem

you can be sure by printing out some of those values in the backtest logs in the meantime.

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. Plain old printf debugging is my friend.