Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
"get_fundamentals" to be deprecated

Hi guys!

The "get_fundamentals" will soon be deprecated and I wonder how can I modify the codes attached to fit them into the pipeline.

For instance, how can I query and filter the companies based on PE ratio?

I also realized some of the valuations ratios are not available under the Fundamentals.valuation_ratios yet. May I know when will this be updated as well?

Thanks for your time!

p/s: codes are modified from sentdex's and Jared Connor's

3 responses

Instead of using the get_fundamentals function, you can simply pass the pe_ratio as a parameter in the screen method of Pipeline. It will look something like this :

        Pipeline( columns = {  
            'Testing factrs': testing_factors,  
            'Bottom Growth Company': bottom_20_secs,  
            'Top Growth Company': top_20_secs,  
        },  
        screen = securities_to_trade & (Fundamentals.pe_ratio.latest > 10) & (Fundamentals.pe_ratio.latest < 30))  

Is it possible to see what the actual PE Ratio is as a column on the Pipeline results?

You can see them by adding them to columns.
Try this: Set a breakpoint on line 57, run it, then type each of these one at a time followed by [enter]:

context.out  
context.out.sort_values(by='pe_ratio', ascending=False).head()  
context.out.sort_values(by='pe_ratio', ascending=False).tail()

I shortened column names for multiple reasons.

    pe_ratio = Fundamentals.pe_ratio.latest

    return Pipeline(  
        columns = {  
            'pe_ratio': pe_ratio,  
            'factrs'  : testing_factors,  
            'BGC'     : bottom_20_secs,  
            'TGC'     : top_20_secs,  
        },  
        screen = securities_to_trade & ((pe_ratio > 10) | (pe_ratio < 30)))  

This includes some code to log the top and bottom 3 also. I always use it.

    if 'log_pipe_done' not in context: log_pipe(context, data)

def log_pipe(context, data):  
        log.info('pipe len {}'.format(len(context.out)))  
        log.info('.\n{}'.format(context.out.sort_values(by='pe_ratio', ascending=False).head(3)))  
        log.info('.\n{}'.format(context.out.sort_values(by='pe_ratio', ascending=False).tail(3)))  
        context.log_pipe_done = 1  

Looks like this

2017-08-07 05:45 log_pipe:65 INFO pipe len 12  
2017-08-07 05:45 log_pipe:66 INFO .  
                        BGC    TGC  factrs   pe_ratio  
Equity(37849 [IPXL])   True  False   131.0  29.166667  
Equity(45503 [AAOI])  False   True  2849.0  22.746479  
Equity(4537 [LRCX])   False   True  2783.0  19.090331  
2017-08-07 05:45 log_pipe:67 INFO .  
                        BGC    TGC  factrs   pe_ratio  
Equity(50595 [BIVV])  False   True  2786.0  14.366372  
Equity(49139 [FIT])    True  False   100.0  13.644444  
Equity(5121 [MU])     False   True  2864.0  12.633484  
End of logs.