Running into the same issue when use get_fundamentals function. Any suggestions?
Code:
def before_trading_start(context, data):
"""
Called every day before market open.
"""
context.output = pipeline_output('my_pipeline')
"""
Called before the start of each trading day.
It updates our universe with the
securities and values found from fetch_fundamentals.
"""
num_stocks = 20
# Setup SQLAlchemy query to screen stocks based on PE ration
# and industry sector. Then filter results based on
# market cap and shares outstanding.
# We limit the number of results to num_stocks and return the data
# in descending order.
fundamental_df = get_fundamentals(
query(
# put your query in here by typing "fundamentals."
fundamentals.operation_ratios.revenue_growth,
fundamentals.valuation_ratios.peg_ratio,
fundamentals.valuation_ratios.forward_pe_ratio,
fundamentals.income_statement.ebit
)
# No Financials (103), Real Estate (104) or Utility (207) Stocks, no ADR or PINK, only USA
.filter(fundamentals.company_reference.country_id == "USA")
.filter(fundamentals.share_class_reference.is_depositary_receipt == False)
.filter(fundamentals.share_class_reference.is_primary_share == True)
# Only pick active stocks
.filter(fundamentals.share_class_reference.share_class_status == "A")
# Only Common Stock
.filter(fundamentals.share_class_reference.security_type == "ST00000001")
.filter(fundamentals.company_reference.primary_exchange_id != "OTCPK")
.filter(fundamentals.valuation.market_cap != None)
.filter(fundamentals.valuation.market_cap >= 2e9)
.filter(fundamentals.valuation.market_cap < 1e100)
.filter(fundamentals.operation_ratios.roic > 0.1)
.filter(fundamentals.valuation.shares_outstanding != None)
.filter(fundamentals.valuation_ratios.ev_to_ebitda != None)
.order_by(fundamentals.operation_ratios.revenue_growth.desc())
.limit(num_stocks)
)
# Filter out only stocks that fits in criteria
context.security_list = [stock for stock in fundamental_df]
print fundamental_df.head(5) # ['forward_pe_ratio']
debug info:
2010-01-04 PRINT security Equity(27993 [LINE]) Equity(36093 [IPI]) Equity(24831 [ESI]) \
revenue_growth 3.895252 2.43894 0.335742
peg_ratio None None None
forward_pe_ratio None None None
ebit 9.13037e+08 8.6269e+07 1.22208e+08
security Equity(36346 [LO]) Equity(23650 [ARO]) Equity(3450 [MNST]) \
revenue_growth 0.261333 0.177997 0.080506
peg_ratio None None None
forward_pe_ratio None None None
ebit 3.93e+08 1.05681e+08 9.2915e+07