EquityQuery#

class yfinance.EquityQuery(operator: str, operand: List[QueryBase] | Tuple[str, Tuple[str | Real, ...]])#

The EquityQuery class constructs filters for stocks based on specific criteria such as region, sector, exchange, and peer group.

Start with value operations: EQ (equals), IS-IN (is in), BTWN (between), GT (greater than), LT (less than), GTE (greater or equal), LTE (less or equal).

Combine them with logical operations: AND, OR.

Example

Predefined Yahoo query aggressive_small_caps:

from yfinance import EquityQuery

EquityQuery('and', [
    EquityQuery('is-in', ['exchange', 'NMS', 'NYQ']),
    EquityQuery('lt', ["epsgrowth.lasttwelvemonths", 15])
])

Attributes

valid_fields

Valid operands, grouped by category.

Permitted Keys/Values#

Key

Values

eq_fields

  • exchange

  • peer_group

  • region

  • sector

price

  • eodprice

  • fiftytwowkpercentchange

  • intradaymarketcap

  • intradayprice

  • intradaypricechange

  • lastclose52weekhigh.lasttwelvemonths

  • lastclose52weeklow.lasttwelvemonths

  • lastclosemarketcap.lasttwelvemonths

  • percentchange

trading

  • avgdailyvol3m

  • beta

  • dayvolume

  • eodvolume

  • pctheldinsider

  • pctheldinst

short_interest

  • days_to_cover_short.value

  • short_interest.value

  • short_interest_percentage_change.value

  • short_percentage_of_float.value

  • short_percentage_of_shares_outstanding.value

valuation

  • bookvalueshare.lasttwelvemonths

  • lastclosemarketcaptotalrevenue.lasttwelvemonths

  • lastclosepriceearnings.lasttwelvemonths

  • lastclosepricetangiblebookvalue.lasttwelvemonths

  • lastclosetevtotalrevenue.lasttwelvemonths

  • pegratio_5y

  • peratio.lasttwelvemonths

  • pricebookratio.quarterly

profitability

  • consecutive_years_of_dividend_growth_count

  • forward_dividend_per_share

  • forward_dividend_yield

  • returnonassets.lasttwelvemonths

  • returnonequity.lasttwelvemonths

  • returnontotalcapital.lasttwelvemonths

leverage

  • ebitdainterestexpense.lasttwelvemonths

  • ebitinterestexpense.lasttwelvemonths

  • lastclosetevebit.lasttwelvemonths

  • lastclosetevebitda.lasttwelvemonths

  • ltdebtequity.lasttwelvemonths

  • netdebtebitda.lasttwelvemonths

  • totaldebtebitda.lasttwelvemonths

  • totaldebtequity.lasttwelvemonths

liquidity

  • altmanzscoreusingtheaveragestockinformationforaperiod.lasttwelvemonths

  • currentratio.lasttwelvemonths

  • operatingcashflowtocurrentliabilities.lasttwelvemonths

  • quickratio.lasttwelvemonths

income_statement

  • basicepscontinuingoperations.lasttwelvemonths

  • dilutedeps1yrgrowth.lasttwelvemonths

  • dilutedepscontinuingoperations.lasttwelvemonths

  • ebit.lasttwelvemonths

  • ebitda.lasttwelvemonths

  • ebitda1yrgrowth.lasttwelvemonths

  • ebitdamargin.lasttwelvemonths

  • epsgrowth.lasttwelvemonths

  • grossprofit.lasttwelvemonths

  • grossprofitmargin.lasttwelvemonths

  • netepsbasic.lasttwelvemonthsnetepsdiluted.lasttwelvemonths

  • netincome1yrgrowth.lasttwelvemonths

  • netincomeis.lasttwelvemonths

  • netincomemargin.lasttwelvemonths

  • operatingincome.lasttwelvemonths

  • quarterlyrevenuegrowth.quarterly

  • totalrevenues.lasttwelvemonths

  • totalrevenues1yrgrowth.lasttwelvemonths

balance_sheet

  • totalassets.lasttwelvemonths

  • totalcashandshortterminvestments.lasttwelvemonths

  • totalcommonequity.lasttwelvemonths

  • totalcommonsharesoutstanding.lasttwelvemonths

  • totalcurrentassets.lasttwelvemonths

  • totalcurrentliabilities.lasttwelvemonths

  • totaldebt.lasttwelvemonths

  • totalequity.lasttwelvemonths

  • totalsharesoutstanding

cash_flow

  • capitalexpenditure.lasttwelvemonths

  • cashfromoperations.lasttwelvemonths

  • cashfromoperations1yrgrowth.lasttwelvemonths

  • forward_dividend_yield

  • leveredfreecashflow.lasttwelvemonths

  • leveredfreecashflow1yrgrowth.lasttwelvemonths

  • unleveredfreecashflow.lasttwelvemonths

esg

  • environmental_score

  • esg_score

  • governance_score

  • highest_controversy

  • social_score

valid_values

Most operands take number values, but some have a restricted set of valid values.

Permitted Keys/Values#

Key

Values

region

ar, at, au, be, br, ca, ch, cl, cn, co, cz, de, dk, ee, eg, es, fi, fr, gb, gr, hk, hu, id, ie, il, in, is, it, jp, kr, kw, lk, lt, lv, mx, my, nl, no, nz, pe, ph, pk, pl, pt, qa, ro, ru, sa, se, sg, sr, th, tr, tw, us, ve, vn, za

exchange

ar: BUE. at: VIE. au: ASX. be: BRU
br: SAO. ca: CNQ, NEO, TOR, VAN
ch: EBS. cl: SGO. cn: SHH, SHZ
co: BVC. cz: PRA
de: BER, DUS, FRA, GER, HAM, MUN, STU
dk: CPH. ee: TAL. eg: CAI. es: MCE
fi: HEL. fr: PAR. gb: AQS, IOB, LSE
gr: ATH. hk: HKG. hu: BUD. id: JKT
ie: ISE. il: TLV. in: BSE, NSI
is: ICE. it: MIL. jp: FKA, JPX, SAP
kr: KOE, KSC. kw: KUW. lk:
lt: LIT. lv: RIS. mx: MEX. my: KLS
nl: AMS. no: OSL. nz: NZE. pe:
ph: PHP, PHS. pk: . pl: WSE
pt: LIS. qa: DOH. ro: BVB. ru:
sa: SAU. se: STO. sg: SES. sr:
th: SET. tr: IST. tw: TAI, TWO
us: ASE, BTS, CXI, NCM, NGM, NMS, NYQ, OEM, OQB, OQX, PCX, PNK, YHD
ve: CCS. vn: . za: JNB

sector

  • Basic Materials

  • Communication Services

  • Consumer Cyclical

  • Consumer Defensive

  • Energy

  • Financial Services

  • Healthcare

  • Industrials

  • Real Estate

  • Technology

  • Utilities

peer_group

  • Aerospace & Defense

  • Auto Components

  • Automobiles

  • Banks

  • Building Products

  • Chemicals

  • China Fund Aggressive Allocation Fund

  • China Fund Equity Funds

  • China Fund QDII Greater China Equity

  • China Fund QDII Sector Equity

  • China Fund Sector Equity Financial and Real Estate

  • Commercial Services

  • Construction & Engineering

  • Construction Materials

  • Consumer Durables

  • Consumer Services

  • Containers & Packaging

  • Diversified Financials

  • Diversified Metals

  • EAA CE Global Large-Cap Blend Equity

  • EAA CE Other

  • EAA CE Sector Equity Biotechnology

  • EAA CE UK Large-Cap Equity

  • EAA CE UK Small-Cap Equity

  • EAA Fund Asia ex-Japan Equity

  • EAA Fund China Equity

  • EAA Fund China Equity - A Shares

  • EAA Fund Denmark Equity

  • EAA Fund EUR Aggressive Allocation - Global

  • EAA Fund EUR Corporate Bond

  • EAA Fund EUR Moderate Allocation - Global

  • EAA Fund Emerging Europe ex-Russia Equity

  • EAA Fund Europe Large-Cap Blend Equity

  • EAA Fund Eurozone Large-Cap Equity

  • EAA Fund Germany Equity

  • EAA Fund Global Emerging Markets Equity

  • EAA Fund Global Equity Income

  • EAA Fund Global Flex-Cap Equity

  • EAA Fund Global Large-Cap Blend Equity

  • EAA Fund Global Large-Cap Growth Equity

  • EAA Fund Hong Kong Equity

  • EAA Fund Japan Large-Cap Equity

  • EAA Fund Other Bond

  • EAA Fund Other Equity

  • EAA Fund RMB Bond - Onshore

  • EAA Fund Sector Equity Consumer Goods & Services

  • EAA Fund Sector Equity Financial Services

  • EAA Fund Sector Equity Industrial Materials

  • EAA Fund Sector Equity Technology

  • EAA Fund South Africa & Namibia Equity

  • EAA Fund Switzerland Equity

  • EAA Fund US Large-Cap Blend Equity

  • EAA Fund USD Corporate Bond

  • Electrical Equipment

  • Energy Services

  • Food Products

  • Food Retailers

  • Healthcare

  • Homebuilders

  • Household Products

  • India CE Multi-Cap

  • India Fund Large-Cap

  • India Fund Sector - Financial Services

  • Industrial Conglomerates

  • Insurance

  • Machinery

  • Media

  • Mexico Fund Mexico Equity

  • Oil & Gas Producers

  • Paper & Forestry

  • Pharmaceuticals

  • Precious Metals

  • Real Estate

  • Refiners & Pipelines

  • Retailing

  • Semiconductors

  • Software & Services

  • Steel

  • Technology Hardware

  • Telecommunication Services

  • Textiles & Apparel

  • Traders & Distributors

  • Transportation

  • Transportation Infrastructure

  • US CE Convertibles

  • US CE Options-based

  • US CE Preferred Stock

  • US Fund China Region

  • US Fund Consumer Cyclical

  • US Fund Diversified Emerging Mkts

  • US Fund Equity Energy

  • US Fund Equity Precious Metals

  • US Fund Financial

  • US Fund Foreign Large Blend

  • US Fund Health

  • US Fund Large Blend

  • US Fund Large Growth

  • US Fund Large Value

  • US Fund Miscellaneous Region

  • US Fund Natural Resources

  • US Fund Technology

  • US Fund Trading–Leveraged Equity

  • Utilities

Methods

__init__(operator: str, operand: List[QueryBase] | Tuple[str, Tuple[str | Real, ...]])
to_dict() Dict