关于 QuantContext
QuantContext 是面向量化研究与交易 Agent 的 MCP 服务,可将自然语言策略转为选股、回测和因子分析流程。计算基于市场数据并可复现,而非由 LLM 生成数值。
主要功能
- 01按基本面和技术指标筛选股票
- 02回测历史策略并输出绩效指标
- 03用 Fama-French 因子拆解收益
- 04组合筛选、回测与分析流程
- 05通过 Python 直接调用工具
适用场景
- 01筛选符合估值和盈利条件的股票
- 02评估动量策略的历史表现
- 03判断策略收益是否来自因子暴露
- 04在脚本中运行回测或因子分析
MCP 相关
MCP 服务提供股票筛选、策略回测和因子分析工具,可供兼容 MCP 的编码 Agent 调用。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
QuantContext
QuantContext 是一个 MCP 服务,可将通俗英语策略描述转化为可执行的量化研究:按任意条件筛选股票、使用历史数据进行回测,并运行因子分析以了解收益来源。所有数值均基于真实市场数据计算,并非由 LLM 生成。结果完全可复现。
适用于 Claude、Codex、OpenCode 或任何兼容 MCP 的编码 Agent。
安装
pip install quantcontext-mcp
Claude Code:
claude mcp add quantcontext -- quantcontext
Claude Desktop(~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"quantcontext": {
"command": "quantcontext"
}
}
}
无需 API 密钥。无需配置。
工具
三个工具可组合成完整的研究工作流:
screen_stocks -> backtest_strategy -> factor_analysis
| 工具 | 功能 |
|---|---|
screen_stocks | 根据基本面、动量、质量、技术信号或多因子组合,筛选 S&P 500、Nasdaq 100 或 Russell 2000 成分股。返回按排名排序的候选股。 |
backtest_strategy | 使用再平衡循环引擎对策略进行历史回测。返回 CAGR、夏普比率、最大回撤、权益曲线和交易日志。 |
factor_analysis | 将策略收益分解为 Fama-French 因子(市场、规模、价值、动量)。返回带 t 统计量的 alpha、因子载荷和 R 平方。 |
示例提示词
股票筛选:
Screen S&P 500 for value stocks: PE under 15, ROE above 12%
Find the top 20% momentum stocks in the Nasdaq 100 over the last 200 days
Rank S&P 500 stocks by a blend of value, momentum, and quality, equal weight each factor
Find S&P 500 stocks with RSI under 40 and price above the 200-day moving average
回测:
Backtest a top-20% momentum strategy on Nasdaq 100, monthly rebalance, last 2 years
How would a value screen (PE under 15, ROE above 12%) have performed on S&P 500 over the last 3 years?
Test a momentum strategy with a 15% stop loss and 20% max portfolio drawdown circuit breaker
完整研究工作流:
Screen S&P 500 for cheap, high-quality stocks. Backtest monthly over 3 years,
then run factor analysis. Is the return real alpha or just factor exposure?
筛选类型
| 筛选 | 描述 | 关键参数 |
|---|---|---|
fundamental_screen | 按 PE、ROE、杠杆率、营收增长筛选 | pe_lt、roe_gt、debt_equity_lt、revenue_growth_gt |
quality_screen | 盈利能力和资产负债表健康状况 | roe_gt、debt_equity_lt、profit_margin_gt |
momentum_screen | 按 N 日价格动量排名 | lookback_days、top_pct |
value_screen | 按估值筛选出价格最低的股票 | pe_lt、top_n |
factor_model | 多因子综合评分 | weights(价值/动量/质量/波动率)、top_n |
technical_signal | RSI 和 SMA 交叉信号 | rsi_period、sma_short、sma_long |
mean_reversion | 低于 z-score 阈值的股票 | lookback_days、z_threshold |
在 Python 中使用
这些工具也可直接导入,无需 Agent。如果你已有脚本,并希望接入回测或因子分析,这会很实用。
from quantcontext.server import screen_stocks, backtest_strategy, factor_analysis
import asyncio, json
# Screen
result = json.loads(asyncio.run(screen_stocks(
universe="sp500",
screen_type="fundamental_screen",
config={"pe_lt": 15, "roe_gt": 12},
)))
# Backtest
bt = json.loads(asyncio.run(backtest_strategy(
stages=[{"order": 1, "type": "screen", "skill": "fundamental_screen", "config": {"pe_lt": 15, "roe_gt": 12}}],
universe="sp500",
rebalance="monthly",
start_date="2022-01-01",
)))
print(bt["metrics"])
# Factor analysis — pipe the equity curve straight in
fa = json.loads(asyncio.run(factor_analysis(
equity_curve=bt["full_equity_curve"]
)))
print(fa["alpha_annualized"], fa["alpha_tstat"])
策略使用上表中的内置筛选类型来表示。所有函数均为异步函数,并返回 JSON 字符串。
数据
所有数据均为公开数据,无需 API 密钥。
| 数据 | 来源 | 缓存 |
|---|---|---|
| 日 OHLCV 价格 | Yahoo Finance(yfinance) | ~/.cache/quantcontext/prices.parquet |
| 基本面数据(PE、ROE、利润率等) | Yahoo Finance | ~/.cache/quantcontext/financials/,TTL 为 24 小时 |
| Fama-French 因子(Mkt-RF、SMB、HML、Mom) | Kenneth French Data Library | ~/.cache/quantcontext/ff_factors.parquet |
| 股票池列表(S&P 500、Nasdaq 100) | Wikipedia | ~/.cache/quantcontext/sp500_tickers.json |
首次调用工具时会下载并缓存数据(10-30 秒)。之后的调用均使用本地缓存:筛选不到 1 秒,回测耗时 3-8 秒。
若要跳过冷启动,请在安装后运行一次:
quantcontext-warmup --url https://quantcontext.ai/api/data
链接
许可证
MIT
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。