mcp战略研究数据库
一种模型上下文协议(MCP)服务器,提供Claude Code对策略研究SQLite数据库的访问,用于分析交易策略回溯测试结果。
特性
- 分析多个市场时期的战略绩效
- 找到适用于所有市场制度的策略(稳健策略)
- 将策略与买入并持有基准进行比较
- 查询风险调整指标(卡尔马比率、夏普比率)
- 寻找超越基准的阿尔法生成策略
- 分析不同符号之间的策略一致性
- 运行自定义SQL查询(只读)以进行高级分析
安装
# Clone the repository
git clone https://github.com/locupleto/mcp-strategy-research-db.git
cd mcp-strategy-research-db
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt配置
设置所需的环境变量:
export STRATEGY_DB_PATH=/path/to/strategy_research.db数据库通常由 trading-lab 项目的战略搜索脚本。
使用克劳德代码注册
MCP服务器可以在两个范围内注册:
项目级别(推荐)
仅为当前项目注册服务器。配置存储在 ~/.claude.json 在项目的路径下。这是针对特定项目工具的推荐方法。
cd /Volumes/Work/development/projects/git/mcp-strategy-research-db
claude mcp add strategy-research-db \
"$(pwd)/venv/bin/python3" \
"$(pwd)/strategy_research_mcp_server.py"这将服务器添加到 ~/.claude.json 在项目的 mcpServers 配置:
{
"projects": {
"/Volumes/Work/development/projects/git/mcp-strategy-research-db": {
"mcpServers": {
"strategy-research-db": {
"type": "stdio",
"command": "/Volumes/Work/development/projects/git/mcp-strategy-research-db/venv/bin/python3",
"args": [
"/Volumes/Work/development/projects/git/mcp-strategy-research-db/strategy_research_mcp_server.py"
]
}
}
}
}
}用户级别(全局)
全局注册服务器,在所有项目中都可用。使用 -s user 标志:
claude mcp add -s user strategy-research-db \
"$(pwd)/venv/bin/python3" \
"$(pwd)/strategy_research_mcp_server.py"验证注册
# List all registered MCP servers
claude mcp list
# Debug mode for troubleshooting
claude --mcp-debug工具(共17个)
数据库概述
| 工具 | 说明 |
|---|---|
get_database_status | 数据库统计:运行、策略、符号、日期范围 |
list_search_runs | 列出所有带有筛选选项的回溯测试运行 |
get_run_details | 获取特定搜索运行的详细信息 |
战略分析
| 工具 | 说明 |
|---|---|
get_top_strategies | 通过可定制的排序和过滤器获得排名靠前的策略 |
get_strategy_details | 获取特定策略ID的完整详细信息 |
compare_strategy_across_periods | 分析战略在不同市场时期的表现 |
跨期稳健性
| 工具 | 说明 |
|---|---|
find_robust_strategies | 找到在所有市场时期都能持续发挥作用的策略 |
get_period_summary | 每个测试市场期的汇总统计数据 |
基准分析
| 工具 | 说明 |
|---|---|
find_alpha_generators | 寻找超越买入并持有基准的策略 |
get_risk_adjusted_rankings | 按卡尔玛比率或其他风险调整指标对策略进行排名 |
符号分析
| 工具 | 说明 |
|---|---|
get_symbol_performance | 按单个符号细分的性能 |
find_best_symbols_for_strategy | 找出哪些符号最适合给定的策略 |
资本配置分析
| 工具 | 说明 |
|---|---|
get_capital_deployment_analysis | 使用市场时间数据分析不同时期的投资组合资本利用率 |
get_daily_position_counts | 从交易级别数据中获取准确的每日头寸计数(需要2025年12月以上的运行) |
compare_timing_modes | 比较保守(T+1)与激进(当天)交易时机 |
高级
| 工具 | 说明 |
|---|---|
run_custom_query | 执行自定义SQL查询(只读) |
get_schema | 获取数据库架构文档 |
list_strategy_ids | 列出具有可选模式过滤的策略ID |
关键指标说明
性能指标
- 期望:每笔交易的预期回报率(%)
- 胜率:获胜交易的百分比
- 盈利因子:毛利/毛利比率
- 复合年增长率:复合年增长率
风险度量
- 最大提款:最大峰谷跌幅
- 卡尔玛比率:复合年增长率/最大提款额(越高=风险调整后的回报越好)
- 夏普比率:相对于无风险利率的风险调整回报
一致性度量
- 一致性得分:策略有利可图的符号百分比
- 超越基准的符号:表现优于买入并持有的交易品种百分比
示例用法
# Get overview of the database
> get_database_status
# Find strategies that work in ALL market periods
> find_robust_strategies min_periods=6 min_consistency=0.7
# Get top strategies for a specific period
> get_top_strategies period_name="2008 Financial Crisis" sort_by="median_calmar_ratio" limit=10
# Compare a strategy across all periods
> compare_strategy_across_periods strategy_id="buy_adm_momentum_low__sell_adm_momentum_high"
# Find alpha generators
> find_alpha_generators min_alpha=5.0 min_beat_rate=0.6数据库模式
SQLite数据库包含四个主要表:
搜索运行
每次回溯测试运行的元数据(研究、期间、日期范围、基准数据)
聚合结果
使用MEDIAN值对所有测试符号进行策略级聚合指标
symbol结果
用于详细分析的每个符号回溯测试结果
贸易结果(2025年12月以上)
包含入/出日期的个人交易记录,用于每日头寸计数分析。随着时间的推移,实现精确的投资组合级资本部署跟踪。
需求
- Python 3.10+
- MCP-SDK(
mcp>=1.23.1) - SQLite策略研究数据库(来自交易实验室项目)
相关项目
trading-lab:战略回溯测试和信号研究平台mcp-marketdata-db:市场数据MCP服务器
许可证
麻省理工学院
