Obtain real-time data on China public funds via AkShare, and screen high-quality fund products based on quantitative indicators.
Features
- In-depth analysis of a single fund: Conduct comprehensive diagnosis of a single fund, including risk indicators, stage returns, annual returns, asset allocation, fund manager, and holdings information
- Whole-market batch screening: Intelligent screening from open-end funds across the whole market, supporting multiple modes
- Result export: Automatically save CSV files
Usage
Running this skill requires Python 3.8+ and dependencies: pip install akshare pandas numpy
# 单基金分析
python fund_screener.py <基金代码> [基金名称]
Pure bond fund screening (low risk)
python fund_screener.py --bond
Fixed income plus fund screeningpython fund_screener.py --gushou-plus
Equity fund screeningpython fund_screener.py --stock
Alpha strategy screening (Calmar ratio)python fund_screener.py --stock-alpha
Custom parameterspython fund_screener.py --bond --min-sharpe 1.0 --max-dd 2 --min-return 2.5 python fund_screener.py --gushou-plus --min-sortino 1.5 python fund_screener.py --stock-alpha --min-calmar 0.8 --min-return 10
Quantity controlpython fund_screener.py --bond --max 50
## 筛选模式与指标
| 模式 | 参数 | 核心指标 | 默认筛选标准 |
|------|------|----------|------------|
| 纯债基金 | `--bond` | 夏普比率 | 夏普>=1.0, 回撤<2%, 收益>2.5% |
| 固收+ | `--gushou-plus` | 索提诺比率 | 夏普>=0.8, 索提诺>=1.2, 回撤<5%, 收益>3.5% |
| 股票Alpha | `--stock-alpha` | 卡玛比率 | 卡玛>=1.2, 回撤<30%, 收益>10% |
| 默认/股票 | 无/`--stock` | 夏普比率 | 夏普>=0.5, 回撤<15%, 收益>3% |
## 自定义参数
| 参数 | 说明 |
|------|------|
| `--min-sharpe <value>` | 最小夏普比率 |
| `--min-sortino <value>` | 最小索提诺比率 |
| `--min-calmar <value>` | 最小卡玛比率 |
| `--max-dd <value>` | 最大回撤百分比(正数,如5表示<5%) |
| `--min-return <value>` | 最小年化收益率(%) |
| `--max <value>` | 最大分析数量(50-500) |
## 作为 Python 模块使用
```python
from fund_screener import get_fund_metrics, analyze_single_fund, calculate_sharpe_ratio
# 分析单只基金
metrics = get_fund_metrics('004010', '华泰柏瑞鼎利混合A')
# 深度分析
analysis = analyze_single_fund('004010')
Data sources
- Fund net value: East Money (via AkShare)
- Fund manager/scale: fund manager holdings data
- Asset allocation: fund quarterly holdings reports
- Data verification: Baidu Stock Connect (via BrowserMCP, optional enhancement)
Browser data verification (BrowserMCP)
Some AkShare data has known biases (fund scale is the manager's total scale rather than the scale of a single fund, holdings data may lag, and there are differences in return calculation standards). When BrowserMCP is available, after Python screening generates the CSV, it should automatically access via browserBaidu Stock Connectto perform data cross-verification and correction.
Prerequisites
.mcp.jsonBrowserMCP is already configured in
Complete workflow
Step 1: 运行Python筛选 → 生成初始CSV
Step 2: 读取CSV,识别A/C份额对,去重
Step 3: 逐只基金通过BrowserMCP访问百度股市通
Step 4: 验证并修正三大数据:规模、持仓、收益
Step 5: 更新CSV + 保存验证缓存JSON
Step 6: 输出修正摘要
Step 2: A/C share deduplication
The A/C shares of the same fund share the same holdings and scale, so there is no need to verify them repeatedly. Deduplication rules:
- Remove the A/B/C/E/H suffix at the end of the fund name for grouping
- Only verify one share per group (prefer the one with the smaller code number)
- Copy the verified holdings and scale data to all shares in the same group
- The trailing 1-year return differs due to fee rate differences, so each share is valued separately (or only the A share is verified)
Step 3: Browser verification protocol
For each unique fund, visit two pages:
3a. Holdings page — obtain the top 5 holdings
URL: https://gushitong.baidu.com/fund/ab-{code}?mainTab=%E6%8C%81%E4%BB%93
Use browser_navigate to visit, then browser_snapshot to get a snapshot. Search for in the snapshot text:
十大重仓股票 更新日期:YYYY-MM-DD
股票A名 X.XX% 股票B名 X.XX% 股票C名 X.XX% ...
Extract the top 5 stock names, connect them with , as the "top 5 holdings".
Exception handling:
- If it shows
十大重仓股票 暂无数据→ keep the original CSV value (common for Hong Kong Stock Connect funds) - If the page times out → retry once, and if it still fails, skip
- If it shows
服务异常→ wait 2 seconds and retry
3b. Profile page — obtain scale and trailing 1-year return
URL: https://gushitong.baidu.com/fund/ab-{code}?mainTab=%E7%AE%80%E5%86%B5
Use browser_navigate to visit, then browser_snapshot to get a snapshot. Search for in the snapshot text:
- Trailing 1-year return: Look for the percentage value near
近一年, such as+53.47% 近一年→ extract53.47 - Fund scale: Look for the value near
规模, in a format such asX.XX亿→ extractX.XX
Note: For some funds, the scale is not directly shown as a numeric value on the overview page; try looking it up from the snapshot on the holdings page.
Step 4: Correct the CSV
For each verified fund:
- If Baidu's "Top 5 Holdings" differ from the CSV → overwrite the CSV with Baidu data
- If Baidu's "Fund Scale" differs from the CSV → overwrite the CSV with Baidu data
- If Baidu's "1-Year Return" differs from the CSV → overwrite the CSV with Baidu data
- For A/C share pairs: sync the holdings and scale data of the A share to the C share
Step 5: Save the verification cache
Update the baidu_fund_data.json file, with the following Schema:
{
"004814": {
"规模": "189.25",
"近1年": "53.63",
"前5大持仓": "紫金矿业, 徐工机械, 新华保险, 中国重汽, 三一重工",
"持仓更新日期": "2025-12-31",
"验证时间": "2026-02-24"
}
}
Step 6: Output the correction summary
After verification is complete, print the summary table:
=== 数据验证摘要 ===
总计检查: 25 只(去重后)
规模修正: 18 只
持仓修正: 14 只
收益修正: 4 只
跳过(暂无数据): 2 只
Performance optimization
- Wait 1-2 seconds after each page load to avoid triggering anti-scraping
- 25 unique funds require about 50 page loads, estimated to take 5-8 minutes
- You can use the cache JSON: if it has already been verified today, skip repeated verification
Risk notice
Historical performance does not represent future performance. This tool is for learning and research only and does not constitute investment advice.