Skip to content

建立 2026-09-15 更新 2026-09-15

篩選器與產業

除了你已經知道代號的標的,yfinance 也能跑 Yahoo 的篩選條件,以及依產業/類股列出成分。適合探索名單,不適合當成嚴格的量化選股引擎。

本頁示範內建篩選字串、自訂 EquityQuery,以及 Sector / Industry

預設篩選

import yfinance as yf

result = yf.screen("aggressive_small_caps")

可用名稱見 yf.PREDEFINED_SCREENER_QUERIES.keys()。把某個 key 對應的查詢取出來,能看到官方幫你組好的條件。

自訂 EquityQuery

以「美股、漲幅大於 3%」為例(欄位名稱以 EquityQuery.valid_fields 為準):

from yfinance import EquityQuery

q = EquityQuery("and", [
    EquityQuery("gt", ["percentchange", 3]),
    EquityQuery("eq", ["region", "us"]),
])
response = yf.screen(q, sortField="percentchange", sortAsc=True)

另有 FundQueryETFQuery 分別篩共同基金與 ETF。說明與參數見 Screener & Queryscreen()

篩選結果仍是 Yahoo 當下的快照,條件與券商「選股」工具不會逐條相等。

Sector 與 Industry

tech = yf.Sector("technology")
software = yf.Industry("software-infrastructure")

tech.overview
tech.top_companies
tech.top_etfs
tech.industries

software.top_performing_companies
software.top_growth_companies

預設區域是美國。可傳 ISO 國家碼縮小範圍:

yf.Sector("technology", region="GB").top_companies

也可從已有的 Ticker.info 串過去:

msft = yf.Ticker("MSFT")
tech = yf.Sector(msft.info.get("sectorKey"))

完整範例見 Sector and Industry