Agent SkillsHKUDS/Vibe-Trading › fundamental-filter

fundamental-filter

GitHub

基于基本面因子(PE/PB/ROE等)筛选股票,支持A股、港股和美股。通过配置数据源与指标,构建价值或成长策略信号,用于量化回测选股。

agent/src/skills/fundamental-filter/SKILL.md HKUDS/Vibe-Trading

Trigger Scenarios

需要基于财务指标筛选股票 构建量化选股策略 获取多市场股票基本面数据

Install

npx skills add HKUDS/Vibe-Trading --skill fundamental-filter -g -y
More Options

Non-standard path

npx skills add https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/fundamental-filter -g -y

Use without installing

npx skills use HKUDS/Vibe-Trading@fundamental-filter

指定 Agent (Claude Code)

npx skills add HKUDS/Vibe-Trading --skill fundamental-filter -a claude-code -g -y

安装 repo 全部 skill

npx skills add HKUDS/Vibe-Trading --all -g -y

预览 repo 内 skill

npx skills add HKUDS/Vibe-Trading --list

SKILL.md

Frontmatter
{
    "name": "fundamental-filter",
    "category": "flow",
    "description": "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)."
}

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)

  1. PE < pe_max AND PE > 0 (exclude loss-making stocks)
  2. PB < pb_max
  3. ROE > roe_min
  4. All conditions met → long (1), otherwise → flat (0)

Growth Filter (Optional)

  1. PE_TTM within reasonable range (0 < PE_TTM < pe_ttm_max)
  2. ROE > roe_min (profitability floor)
  3. 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 the same yfinance interface
hk_tickers = ["0700.HK", "9988.HK", "1810.HK", "2318.HK", "0005.HK"]
results = screen_us_stocks(hk_tickers, criteria)  # Same function works

Parameters

Parameter Default Description
pe_max 20.0 PE ceiling (exclude overvalued)
pb_max 3.0 PB ceiling
roe_min 8.0 ROE floor (%), exclude low-profitability
pe_min 0.0 PE floor (exclude loss-making stocks)
mcap_min 0 Market cap floor (for US/HK, in USD)

Common Pitfalls

  • extra_fields columns may contain NaN (new listings, ST stocks) — must fillna or dropna
  • fundamental_fields columns are prefixed by table and may be NaN before the first statement is published in the backtest window
  • Do not forward-fill statement rows manually before their ann_date / f_ann_date; the runner's merge already enforces point-in-time visibility
  • Negative PE means loss-making — always filter with pe > 0
  • ROE units differ: tushare uses percentage (e.g., 15 = 15%), yfinance uses decimal (e.g., 0.15 = 15%)
  • For portfolio strategies: N stocks passing the screen each get weight 1/N
  • yfinance Ticker.info is a point-in-time snapshot, not historical time-series — cannot directly use for daily rebalancing backtests on US/HK stocks
  • For US/HK daily fundamental backtests, consider using the screening results as a stock universe, then applying technical signals within that universe

Dependencies

pip install pandas numpy yfinance

Signal Convention

  • 1/N = selected for long (N = number of stocks passing the screen), 0 = not selected

Version History

  • 0aa45a9 Current 2026-07-24 17:46

Same Skill Collection

agent/src/skills/adr-hshare/SKILL.md
agent/src/skills/akshare/SKILL.md
agent/src/skills/alpha-zoo/SKILL.md
agent/src/skills/ashare-pre-st-filter/SKILL.md
agent/src/skills/asset-allocation/SKILL.md
agent/src/skills/backtest-diagnose/SKILL.md
agent/src/skills/behavioral-finance/SKILL.md
agent/src/skills/candlestick/SKILL.md
agent/src/skills/ccxt/SKILL.md
agent/src/skills/chanlun/SKILL.md
agent/src/skills/commodity-analysis/SKILL.md
agent/src/skills/corporate-events/SKILL.md
agent/src/skills/correlation-analysis/SKILL.md
agent/src/skills/correlation-regime/SKILL.md
agent/src/skills/cross-market-strategy/SKILL.md
agent/src/skills/crypto-derivatives/SKILL.md
agent/src/skills/data-routing/SKILL.md
agent/src/skills/defi-yield/SKILL.md
agent/src/skills/dividend-analysis/SKILL.md
agent/src/skills/doc-reader/SKILL.md
agent/src/skills/earnings-forecast/SKILL.md
agent/src/skills/earnings-revision/SKILL.md
agent/src/skills/eastmoney/SKILL.md
agent/src/skills/edgar-sec-filings/SKILL.md
agent/src/skills/elliott-wave/SKILL.md
agent/src/skills/event-driven/SKILL.md
agent/src/skills/execution-model/SKILL.md
agent/src/skills/factor-research/SKILL.md
agent/src/skills/fund-analysis/SKILL.md
agent/src/skills/geopolitical-risk/SKILL.md
agent/src/skills/global-macro/SKILL.md
agent/src/skills/harmonic/SKILL.md
agent/src/skills/hedging-strategy/SKILL.md
agent/src/skills/hk-connect-flow/SKILL.md
agent/src/skills/ichimoku/SKILL.md
agent/src/skills/investor-lenses/SKILL.md
agent/src/skills/liquidation-heatmap/SKILL.md
agent/src/skills/macro-analysis/SKILL.md
agent/src/skills/market-microstructure/SKILL.md
agent/src/skills/minute-analysis/SKILL.md
agent/src/skills/ml-strategy/SKILL.md
agent/src/skills/mootdx/SKILL.md
agent/src/skills/multi-factor/SKILL.md
agent/src/skills/okx-market/SKILL.md
agent/src/skills/onchain-analysis/SKILL.md
agent/src/skills/options-advanced/SKILL.md
agent/src/skills/options-payoff/SKILL.md
agent/src/skills/options-strategy/SKILL.md
agent/src/skills/pair-trading/SKILL.md

Metadata

Files
0
Version
e897f59
Hash
056da858
Indexed
2026-07-24 17:46

ホーム - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-22 04:27
浙ICP备14020137号-1 $お客様$