fundamental-filter
它能做什么
这项技能使用市盈率、市净率和净资产收益率等财务指标来筛选股票。适合希望构建价值或成长型筛选并进行检验的投资者。
适用场景
- ✓当你想用 PE 和 PB 等指标筛选价值型股票的时候。
- ✓当你想要一个排除极小型或亏损公司的成长型筛选的时候。
- ✓当你想把基本面筛选作为回测策略进行检验的时候。
技能链接
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/fundamental-filter/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为 A 股建立一个低 PE、低 PB 且 ROE 尚可的价值筛选,然后进行回测。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会从各市场的数据源获取基本面数据,应用筛选条件,并在每个日期将每只股票标记为持有或不持有。然后它会使用这些选股结果运行回测,并针对每个市场使用适合的数据源。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Fundamental Factor Screening
Purpose
Filter stocks using fundamental financial data (PE/PB/ROE, etc.) to build value or growth screen signals for backtesting. Supports multiple markets with different data sources.
Market Support
| Market | Data Source | Method | Supported Metrics |
|---|---|---|---|
| A-shares | tushare daily_basic |
extra_fields in config.json |
pe, pb, pe_ttm, ps_ttm, dv_ttm, total_mv, circ_mv, roe |
| A-shares | Tushare statements | fundamental_fields in config.json |
income, balancesheet, cashflow, fina_indicator fields |
| US stocks | yfinance Ticker.info |
Direct API call | trailingPE, forwardPE, priceToBook, returnOnEquity, marketCap, dividendYield |
| HK stocks | yfinance Ticker.info |
Direct API call | trailingPE, priceToBook, returnOnEquity, marketCap |
Signal Logic
Value Filter (Default)
- PE < pe_max AND PE > 0 (exclude loss-making stocks)
- PB < pb_max
- ROE > roe_min
- All conditions met → long (1), otherwise → flat (0)
Growth Filter (Optional)
- PE_TTM within reasonable range (0 < PE_TTM < pe_ttm_max)
- ROE > roe_min (profitability floor)
- Market cap > mv_min (exclude micro-caps)
A-Share Usage (tushare)
config.json
{
"source": "tushare",
"codes": ["000001.SZ", "600036.SH", "000858.SZ"],
"start_date": "2023-01-01",
"end_date": "2024-12-31",
"extra_fields": ["pe", "pb", "pe_ttm", "roe", "total_mv"],
"initial_cash": 1000000,
"commission": 0.001
}
The extra_fields columns are automatically merged into the daily DataFrame by the DataLoader.
A-Share Statement Pre-Filter
Use fundamental_fields when the strategy needs PIT-safe financial statement data instead of daily valuation fields:
{
"source": "tushare",
"codes": ["000001.SZ", "600036.SH", "000858.SZ"],
"start_date": "2023-01-01",
"end_date": "2024-12-31",
"fundamental_fields": {
"income": ["total_revenue", "n_income"],
"balancesheet": ["total_hldr_eqy_exc_min_int"],
"fina_indicator": ["roe", "debt_to_assets"]
},
"initial_cash": 1000000,
"commission": 0.001
}
The backtest runner queries the configured tables through TushareFundamentalProvider and merges each published statement snapshot into daily bars only after its announcement/disclosure date. Statement columns are prefixed by table name:
| Requested field | SignalEngine column |
|---|---|
income.total_revenue |
income_total_revenue |
income.n_income |
income_n_income |
balancesheet.total_hldr_eqy_exc_min_int |
balancesheet_total_hldr_eqy_exc_min_int |
fina_indicator.roe |
fina_indicator_roe |
Representative financial-quality pre-filter:
revenue = row.get("income_total_revenue")
profit = row.get("income_n_income")
net_assets = row.get("balancesheet_total_hldr_eqy_exc_min_int")
roe = row.get("fina_indicator_roe")
passes = (
revenue is not None and revenue > 0
and profit is not None and profit > 0
and net_assets is not None and net_assets > 0
and roe is not None and roe >= 8.0
)
HK/US Stock Usage (yfinance)
For HK/US stocks, fundamental data is not available as daily time-series via the backtest loader. Instead, use yfinance Ticker info for point-in-time screening:
import yfinance as yf
def screen_us_stocks(tickers, criteria):
"""Screen US/HK stocks by fundamental criteria."""
passed = []
for symbol in tickers:
info = yf.Ticker(symbol).info
pe = info.get("trailingPE")
pb = info.get("priceToBook")
roe = info.get("returnOnEquity") # Decimal (e.g., 0.25 = 25%)
mcap = info.get("marketCap")
if pe is None or pb is None or roe is None:
continue # Skip stocks with missing data
if (0 < pe < criteria["pe_max"]
and pb < criteria["pb_max"]
and roe > criteria["roe_min"]
and (mcap or 0) > criteria.get("mcap_min", 0)):
passed.append({
"symbol": symbol,
"pe": pe,
"pb": pb,
"roe": round(roe * 100, 1), # Convert to percentage
"mcap": mcap,
})
return passed
# Example: screen S&P 500 components
criteria = {"pe_max": 20, "pb_max": 3.0, "roe_min": 0.08, "mcap_min": 10_000_000_000}
results = screen_us_stocks(["AAPL", "MSFT", "JNJ", "JPM", "XOM"], criteria)
HK Stock Screening
# HK stocks use
常见问题
亏损的股票会被排除吗?
在价值筛选中会。它要求 PE 为正,因此亏损股票不会被选中。
支持哪些市场?
A 股、美股和港股,每个市场都有自己的数据源。
阈值从哪里来?
由你在配置中设置,技能会将其作为条件应用。
详情
作者的原始描述
Fundamental factor screening — filter stocks by PE/PB/ROE, financial statement fields, and other metrics for value or growth selection. Supports A-shares (via tushare extra_fields or fundamental_fields) and HK/US stocks (via yfinance Ticker info).
repo: HKUDS/Vibe-Trading
热度
- GitHub 星标
- 37k
- 排名
- #7520
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …