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 分