Back to Community
Percentile_between(x, y) function for fundamental filters

I've been trying to create a basic value screener using the fundamental_df query and was wondering if there's a way to filter for the top 10% of a given value metric. I know the morningstar fundamental data pipeline has the capability ".percentile_between(90, 100)" but it seems like their data doesn't go back before 2014 when I run the backtest. For example:

def before_trading_start(context, data):
num_stocks = 50
fundamental_df = get_fundamentals(
query(
fundamentals.valuation_ratios.pe_ratio,
fundamentals.valuation_ratios.peg_ratio,
fundamentals.valuation_ratios.pb_ratio,
fundamentals.earnings_report.diluted_eps,
fundamentals.valuation_ratios.book_value_per_share,
fundamentals.asset_classification.morningstar_sector_code
)
.filter(fundamentals.valuation.market_cap >= 100e6)
.filter(fundamentals.valuation.shares_outstanding != None)

.filter(fundamentals.valuation_ratios.ev_to_ebitda <= 20.0)

For that last line: " .filter(fundamentals.valuation_ratios.ev_to_ebitda <= 20.0) " is there a way to change this to the top 10% ev_to_ebitda instead of using the " <= " operator?

Thanks for any help!