QuantContext

io.github.zomma-dev由 GitHub 账号 zomma-dev 发布v0.1.2更新于 Oct 24, 2026

Deterministic stock screening, backtesting, and factor analysis for AI trading agents

已验证STDIO仅桌面金融数据与分析

概览

AI 生成的概览

让助手基于真实市场数据筛选股票、回测交易策略并进行因子分析。

可以做什么
QuantContext 提供三个可串联成研究流程的工具:screen_stocks 按基本面、动量、质量、技术信号或多因子组合筛选标普 500、纳斯达克 100 或罗素 2000 成分股;backtest_strategy 用再平衡循环引擎做历史回测,返回 CAGR、夏普比率、最大回撤、净值曲线和交易记录;factor_analysis 将收益分解为 Fama-French 因子,返回 alpha、t 统计量、因子载荷和 R 方。这些函数也可直接从 Python 导入。结果由市场数据计算得出,而非由模型生成。
适用场景
适合助手回答量化股票问题:按条件筛选并排序股票、检验某条规则策略在历史上的表现,或区分真实 alpha 与因子暴露。适用于研究与探索,不用于实盘交易。
运行要求
以 PyPI 包(quantcontext-mcp)形式通过 stdio 在本地运行,通常用 uvx 启动或用 pip 安装。未声明需要 API 密钥或配置。首次使用需要联网下载价格、基本面、Fama-French 因子和指数成分列表,之后缓存在 ~/.cache/quantcontext;首次调用约需 10-30 秒。
安装前请注意
README 提到一个可选的预热命令,会从远程地址获取数据;默认数据来源包括 Yahoo Finance、Kenneth French 数据仓库和 Wikipedia,因此请求会离开本机。缓存的市场数据会写入本地缓存目录。该服务器被描述为仅限桌面端,不执行交易也不涉及资金。

安装

在 SourceWeft 中

  1. 打开 控制台中的 QuantContext,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

QuantContext

QuantContext is an MCP server that turns plain-English strategy descriptions into executable quant research: screen stocks by any criteria, backtest over historical data, and run factor analysis to see where the returns come from. Every number is computed from real market data, not generated by an LLM. Results are fully reproducible.

Works with Claude, Codex, OpenCode, or any other MCP-compatible coding agent.

Install

bash
pip install quantcontext-mcp

Claude Code:

bash
claude mcp add quantcontext -- quantcontext

Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json):

json
{  "mcpServers": {    "quantcontext": {      "command": "quantcontext"    }  }}

No API keys. No configuration.

Tools

Three tools that compose into a full research workflow:

screen_stocks -> backtest_strategy -> factor_analysis
ToolWhat it does
screen_stocksFilter S&P 500, Nasdaq 100, or Russell 2000 by fundamentals, momentum, quality, technical signals, or a multi-factor blend. Returns ranked candidates.
backtest_strategyTest a strategy over history with a rebalance-loop engine. Returns CAGR, Sharpe, max drawdown, equity curve, and trade log.
factor_analysisDecompose strategy returns into Fama-French factors (market, size, value, momentum). Returns alpha with t-statistic, factor loadings, and R-squared.

Sample Prompts

Stock screening:

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

Backtesting:

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

Full research workflow:

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?

Screen Types

ScreenDescriptionKey parameters
fundamental_screenFilter by PE, ROE, leverage, revenue growthpe_lt, roe_gt, debt_equity_lt, revenue_growth_gt
quality_screenProfitability and balance sheet healthroe_gt, debt_equity_lt, profit_margin_gt
momentum_screenRank by N-day price momentumlookback_days, top_pct
value_screenCheapest stocks by valuationpe_lt, top_n
factor_modelMulti-factor composite scoreweights (value/momentum/quality/volatility), top_n
technical_signalRSI and SMA crossover signalsrsi_period, sma_short, sma_long
mean_reversionStocks below z-score thresholdlookback_days, z_threshold

Use from Python

The tools are also importable directly — no agent required. Useful if you have an existing script and want to plug in backtesting or factor analysis.

python
from quantcontext.server import screen_stocks, backtest_strategy, factor_analysisimport asyncio, json
# Screenresult = json.loads(asyncio.run(screen_stocks(    universe="sp500",    screen_type="fundamental_screen",    config={"pe_lt": 15, "roe_gt": 12},)))
# Backtestbt = 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 infa = json.loads(asyncio.run(factor_analysis(    equity_curve=bt["full_equity_curve"])))print(fa["alpha_annualized"], fa["alpha_tstat"])

Strategies are expressed using the built-in screen types from the table above. All functions are async and return JSON strings.

Data

All public data, no API keys required.

DataSourceCache
Daily OHLCV pricesYahoo Finance (yfinance)~/.cache/quantcontext/prices.parquet
Fundamentals (PE, ROE, margins, etc.)Yahoo Finance~/.cache/quantcontext/financials/, 24h TTL
Fama-French factors (Mkt-RF, SMB, HML, Mom)Kenneth French Data Library~/.cache/quantcontext/ff_factors.parquet
Universe lists (S&P 500, Nasdaq 100)Wikipedia~/.cache/quantcontext/sp500_tickers.json

The first tool call downloads and caches data (10-30 seconds). All subsequent calls use the local cache: screening under 1s, backtesting 3-8s.

To skip the cold start, run once after install:

bash
quantcontext-warmup --url https://quantcontext.ai/api/data

Links

  • Docs — full reference, examples, methodology
  • PyPI

License

MIT

来源:README.md,提交 00bc2e7

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.2最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分