Hello,
I'm trying to develop a value algorithm. I get really strange values for fundamentals.
Here is my request:
fundamental_df = get_fundamentals(
query(
# To add a metric. Start by typing "fundamentals."
fundamentals.operation_ratios.roic,
fundamentals.valuation_ratios.pb_ratio
)
# No Financials (103) and Real Estate (104) Stocks, no ADR or PINK, only USA
.filter(fundamentals.asset_classification.morningstar_sector_code != 103)
.filter(fundamentals.company_reference.country_id == "USA")
.filter(fundamentals.asset_classification.morningstar_sector_code != 104)
.filter(fundamentals.share_class_reference.is_depositary_receipt == False)
.filter(fundamentals.share_class_reference.is_primary_share == True)
.filter(fundamentals.company_reference.primary_exchange_id != "OTCPK")
# Check for data sanity (i,e. avoid division by zero)
.filter(fundamentals.valuation.market_cap > 10000000)
.filter(fundamentals.valuation.shares_outstanding > 0)
.filter(fundamentals.balance_sheet.invested_capital > 0)
.filter(fundamentals.balance_sheet.common_stock_equity>0)
.filter(fundamentals.balance_sheet.invested_capital != fundamentals.balance_sheet.cash_and_cash_equivalents)
.order_by(fundamentals.valuation_ratios.pb_ratio.asc())
.limit(num_stocks)
)
With the debugger, I display the data:
fundamental_df: DataFrame
0_Security(20281 [SBAC]): Series
0_roic: -0.014446
1_pb_ratio: 0.0772
1_Security(22720 [GEN]): Series
0_roic: 0.0772
1_pb_ratio: -0.014446
2_Security(20160 [TWTC]): Series
0_roic: -0.014446
1_pb_ratio: 0.0772
3_Security(23798 [NPO]): Series
0_roic: 0.0772
1_pb_ratio: -0.014446
4_Security(15230 [TIE]): Series
This looks really odd. See the alternating values. It is not ordered by the criteria. Looks like corrupted memory, or I overlooked something.
Regards