Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to filter by stocks without a dividend using the pipeline?

How do you filter by stocks with no dividend using the pipeline?

class DividendYield(CustomFactor):  
    """  
    Computes the difference between the highest high and the lowest  
    low of each over an arbitrary input range.  
    """  
    inputs = [valuation_ratios.dividend_yield]

    def compute(self, today, assets, out, dividend_yield):  
        out[:] = dividend_yield  

This gives me 3 stocks:

dyield = DividendYield(window_length=1)  
no_dividend = (dyield <= 0.001)  

This gives me 0:

dyield = DividendYield(window_length=1)  
no_dividend = (dyield == None)  

It looks like when you attempt to do equality it doesn't overload __eq__ so it just does a straight comparison, which is always False.

3 responses

James

Your use of the custom factor and associated filter seem ok. The Morningstar data just seems off (or at least not what's expected).

I've found the best way to troubleshoot (and validate) things is to use the notebook feature. I've attached a notebook that shows the pipeline output of a dividend_yield custom factor and then various filters. The output doesn't seem to match the dividend yield found on Google Finance. (Note when running the pipeline and comparing to external sources make sure to change the date in the run_pipline call to be the current date.)

Dan

I figured it out:

dyield = DividendYield(window_length=1)
no_dividend = ~(dyield > 0.0)

so you have to say "not greater than 0" and that will include records where it is undefined (which shows up as NaN)

They should really fix equality though. Their documentation says it has a SQLAlchemy like interface but this is a glaring hole that is missing. You wouldn't expect greater than to work and return a class but equality to return a boolean.

Ok I see what you're saying about the morning star data. So far what I'm seeing is that if a security gives out monthly dividends it'll be NaN. I'm going to try something else to see if it pays out dividends.