Back to Community
How to store ratios for fundamental data.

I am trying to compute various ratios using fundamental data. For this I will be using a dictionary to store the values thereafter but I am unable to compute the ratios or the mathematical expression (as I am planning to make it more complex if this works). But it gives me an error saying :
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

for this line of code ---> ad_ratio = (assets/debt)

sec_dict = {}  
    for stock in fundamental_df:  
        sector = fundamental_df[stock]['morningstar_sector_code']  
        assets = fundamental_df[stock]['net_assets']  
        debt = fundamental_df[stock]['net_debt']  
        ad_ratio = (assets/debt)  
1 response

That error, TypeError: unsupported operand type(s) for /: 'NoneType' and 'float', shows that it is trying to divide a variable of no type (NoneType) with a float (which is a precise number, for example 5.674). This means that, at some point when you start running your algorithm, assets is of type None, meaning it is not a defined number.

This can be for a number of reasons — likely, there is missing data from the exchange or from Morningstar at that point which may happen regularly when there is no new data or when Morningstar is uncertain about a metric.

You will want to check that assets (and anything else) are defined. You could do this with if assets is not None:, for example. Good luck!


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.