Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help - Simple multiplication gone awry
TypeError: unsupported operand type(s) for *: 'float' and 'ABCMeta' ...  

Hello all,

I'm having a bit of trouble with an algo I've been working on. I would like to do a 'fact check' if you will and see if a stock is a good vale for its expected growth. To do so, I'd like to check its forward earning's yield (the float in the error) against that of the industry (the ABCMeta). However, when I try to run the backtest with a later filter I am informed I'm trying to multiply a float by and ABCMeta. I'm not familiar with ABCMeta, nor am I familiar with what it does, or how its been output from my code for that matter, but attached below is where it is born.

Any thoughts on how I can right this wrong? I'm just trying to get the below code to produce a number for each individual stock.

Thanks a ton in advance!

class Ind_forward_e_yield(CustomFactor):  
        window_length = 1  
        inputs = [morningstar.valuation_ratios.forward_earning_yield,  
                  morningstar.asset_classification.morningstar_industry_code]  
        def compute(self, today, assets, out, forward_earning_yield, industries):  
            df = pd.DataFrame(index=assets, data={  
                    "forward_e_yield": forward_earning_yield[-1],  
                    "industry_codes": industries[-1]  
                 })  
            df.reset_index(inplace=True)  
            adf = df[df['industry_codes'] != -1].groupby(['industry_codes'])['forward_e_yield'].mean()  
            adf = adf.to_frame('industry_forward_e_yield')  
            adf.reset_index(inplace=True)  
            df = df.merge(adf, how='outer', on='industry_codes')  
            df = df.set_index('index')  
            df.fillna(df.min()).mean(axis=1)  
            df.sort_index(inplace=True)  
            out[:] = df['industry_forward_e_yield'].values  
2 responses

Here is where the error actually occurs (when the ABC Meta produced above is multiplied against a float)

eps_filter = forward_e_yield > (1.05 * (Ind_forward_e_yield))  

Just a guess... 'forward_e_yield' I assume is an instance of a factor. However, 'Ind_forward_e_yield' is a class (isn't instantiated'). Probably is complaining because you are multiplying a float by a class. One of the below might fix it??

# Note the added pair of parenthesis  
eps_filter = forward_e_yield > (1.05 * (Ind_forward_e_yield()))  

my_ind_forward_e_yield = Ind_forward_e_yield()  
eps_filter = forward_e_yield > (1.05 * (my_ind_forward_e_yield))