Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
The pe_ratio are wrong? Or my code are wrong?

Hi,

I wrote a very simple program just to check one fundamental data, the 'pe ration'. My program looks as follow. After I run this, I got the printed result as follow:

import numpy as np

# This function is run once at the beginning of the algorithm, REQUIRED  
def initialize(context):  
    # AAPL stock  
    # context.stock = sid(24)  
    # SPY stock  
    # context.market = sid(8554)  
    pass  
# This function is run once per day before any calls to handle_data, OPTIONAL  
def before_trading_start(context, data):  
    #Fundamentals Reference Page: https://www.quantopian.com/help/fundamentals  
    context.fundamental_df = get_fundamentals(  
        query(  
            #fundamentals.income_statement.total_revenue  
            fundamentals.valuation_ratios.pe_ratio  
        )  
        .filter(  
            fundamentals.valuation.market_cap > 30000000000  
        )  
        .order_by(  
            #fundamentals.valuation.market_cap.desc()  
            fundamentals.valuation_ratios.pe_ratio.desc()  
        )  
        .limit(5)  
    )  
    update_universe(context.fundamental_df.columns.values)  
    for stock in data:  
        print '%s - pe ratio: %.2f' % (stock.symbol, context.fundamental_df[stock][0])  
# This function is run once per bar, REQUIRED  
def handle_data(context, data):  
    pass  
def check_mean(context, data):  
    pass  

... 2016-02-17PRINTAGN - pe ratio: 652.35
2016-02-17PRINTSU - pe ratio: 481.12
2016-02-17PRINTAMZN - pe ratio: 392.55
2016-02-17PRINTCRM - pe ratio: 5000.00
2016-02-17PRINTRBS - pe ratio: 670.36
2016-02-18PRINTAGN - pe ratio: 652.35
2016-02-18PRINTSU - pe ratio: 481.12
2016-02-18PRINTAMZN - pe ratio: 403.23
2016-02-18PRINTCRM - pe ratio: 5000.00
2016-02-18PRINTRBS - pe ratio: 670.36

But I check in google/finance and barchart, The 'pe ratio' are much smaller.

Where is the problem?

Regards