qlib-mcp

qlib-mcp

An MCP server for the Microsoft Qlib quantitative research platform that enables AI agents to perform financial data queries, factor analysis, and strategy backtesting. It supports A-share and US stock markets through Qlib expressions and built-in analytical tools.

Category
Visit Server

README

qlib-mcp

全网首个 Microsoft Qlib 量化研究平台的 MCP Server — 让 AI Agent 直接调用 Qlib 做数据查询、因子分析和策略回测。

License: MIT Python MCP Qlib


功能概览

工具 说明
qlib_init 初始化 Qlib 数据环境(必须首先调用)
qlib_download_data 获取 A 股/美股数据集下载命令
qlib_list_instruments 查询 CSI300/CSI500 等指数成分股列表
qlib_get_data 查询历史价格与因子数据(支持 Qlib 表达式)
qlib_backtest_topk TopK 动量策略回测,返回年化收益/夏普/最大回撤
qlib_factor_analysis IC 分析 + 分位数收益,快速验证因子有效性
qlib_expression_help 表达式语法帮助(算子列��� / Alpha158 说明)

安装

前置依赖

# Python 3.10+(推荐 3.12)
pip install pyqlib mcp

下载 Qlib 数据(A 股日线,约 500MB)

python -m qlib.run.get_data qlib_data \
  --target_dir ~/.qlib/qlib_data/cn_data \
  --region cn

注册到 MCP 客户端

Claude Desktop / mcporter / Cursor:

{
  "mcpServers": {
    "qlib": {
      "command": "python",
      "args": ["/path/to/qlib-mcp/server.py"],
      "description": "Microsoft Qlib 量化研究平台"
    }
  }
}

请将 python 替换为你实际的 Python 路径(如 /Users/你/.pyenv/versions/3.12.12/bin/python


使用示例

1. 初始化

调用 qlib_init,data_path = "~/.qlib/qlib_data/cn_data",region = "cn"

2. 查询 CSI300 成分股

调用 qlib_list_instruments,market = "csi300",start_date = "2024-01-01"

3. 获取平安银行近 60 日收盘价

调用 qlib_get_data,symbols = "SZ000001",fields = "$close,$volume",start_date = "2024-10-01"

4. 20 日动量因子 IC 分析

调用 qlib_factor_analysis,factor_expr = "$close / Ref($close, 20) - 1"

5. TopK 策略回测(CSI300,2020-2023)

调用 qlib_backtest_topk,market = "csi300",topk = 50,signal_field = "$close / Ref($close, 20) - 1"

Qlib 表达式语法速查

# 价格动量
$close / Ref($close, 20) - 1      # 20 日动量

# 技术指标
EMA($close, 12) - EMA($close, 26) # MACD
($close - Mean($close, 20)) / Std($close, 20)  # 布林带位置

# 成交量因子
$volume / Mean($volume, 20)        # 相对成交量
Corr($close, $volume, 10)          # 价量相关性(聪明钱)

完整算子列表:调用 qlib_expression_help(topic="operators")


受支持的市场

区域 常用成分股池
A 股(cn) all, csi300, csi500, csi100, sz50
美股(us) sp500, nasdaq100

许可证

MIT License


相关链接

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured