Skip to main content

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

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"
    }
  }
}

No API keys. No configuration.

Tools

Three tools that compose into a full research workflow:

screen_stocks -> backtest_strategy -> factor_analysis
Tool What it does
screen_stocks Filter S&P 500, Nasdaq 100, or Russell 2000 by fundamentals, momentum, quality, technical signals, or a multi-factor blend. Returns ranked candidates.
backtest_strategy Test a strategy over history with a rebalance-loop engine. Returns CAGR, Sharpe, max drawdown, equity curve, and trade log.
factor_analysis Decompose 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

Screen Description Key parameters
fundamental_screen Filter by PE, ROE, leverage, revenue growth pe_lt, roe_gt, debt_equity_lt, revenue_growth_gt
quality_screen Profitability and balance sheet health roe_gt, debt_equity_lt, profit_margin_gt
momentum_screen Rank by N-day price momentum lookback_days, top_pct
value_screen Cheapest stocks by valuation pe_lt, top_n
factor_model Multi-factor composite score weights (value/momentum/quality/volatility), top_n
technical_signal RSI and SMA crossover signals rsi_period, sma_short, sma_long
mean_reversion Stocks below z-score threshold lookback_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.

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"])

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.

Data Source Cache
Daily OHLCV prices Yahoo 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:

quantcontext-warmup --url https://quantcontext.ai/api/data
  • Docs — full reference, examples, methodology
  • PyPI

License

MIT

Metadata

Release files for quantcontext-mcp 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quantcontext-mcp 0.1.2
File Size Uploaded Provenance
quantcontext_mcp-0.1.2.tar.gz 739.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for quantcontext-mcp 0.1.2
File Interpreter ABI Platform
quantcontext_mcp-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 771.7 kB

Release files / quantcontext_mcp-0.1.2.tar.gz

Download URL quantcontext_mcp-0.1.2.tar.gz
Size 739.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c27cf3207774e725c7b96aaaf4a65dceda813a968309a9cd8e0a3de5c1481b01
BLAKE2b-256 checksum
How to use checksums
aea56b0d8fa5ad2587064638dfc00c072242b6f00389c4a974fea2c2f4ec6910
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / quantcontext_mcp-0.1.2-py3-none-any.whl

Download URL quantcontext_mcp-0.1.2-py3-none-any.whl
Size 32.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6f45137195a3445bbfbc4e365f8442e9107f113a4d207b7b579b934421ea04d
BLAKE2b-256 checksum
How to use checksums
9df438afd9ea275e4c82a4e7cf4f4a34137389692b5de8430b408ceb8cc09a88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for quantcontext-mcp 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page