证券分析工具

一个基于Python的证券分析流程,使用模型上下文协议(MCP)进行市场数据解析、分析和可视化,适用于金融研究和投资决策。

  • by druce
  • Python
  • 本地部署
  • 8 星标
  • 更新于

使用说明

MCP证券分析

基于Python的证券分析流程 **模型上下文协议(MCP)**该存储库将市场数据、解析、分析和可视化工具捆绑在FastMCP服务器后面,以便任何支持MCP的客户端(如Claude Desktop、LangChain)都可以在本地或远程使用它们。

特斯拉深度研究报告示例.

此报告是通过以下步骤半自主生成的:

  • 将MCP工具连接到Claude Desktop,包括网络搜索、困惑、维基百科。(参见 claude_desktop_config.json 详细信息)。你可以把维基百科工具想象成你邀请的一个朋友,他知道如何搜索和浏览维基百科,并将文章、章节、摘要带入聊天环境,以便与用户和人工智能进行进一步讨论。

  • 连接 server.py MCP服务器连接到克劳德桌面。把这想象成用Python编写自己的机器人,可以将内容带入聊天环境:市场数据、SEC文件或任何其他你可以检索或计算的东西。

  • 提示Claude Desktop查询困惑、维基百科和10-K,将特斯拉的信息带入上下文。

  • 提示Claude Desktop查询市场数据工具以获取特斯拉的最新信息

  • 最后,进行深入研究,并促使Claude Desktop使用从聊天上下文、其他网络搜索和工具调用中检索到的信息,分8个部分编写一份深度报告,详细说明每个部分应该涵盖的内容。

  • 看见 prompts.txt 用于示例中使用的提示。

虽然它不是一个完全自主的代理,而且处于早期的POC级别,但它展示了迈向完全自主代理的道路。创建一个MCP客户端,该客户端自主完成上述步骤,并以结构化格式生成关于特斯拉的深度报告,包括图表。或者创造一个更先进的 多代理工作流 每个部分都有一组并行代理、一个评论家优化器工作流和一个最终报告生成器。

server.py功能

  • FastMCP服务器 – server.py 暴露一些MCP 工具 从公共网站、订阅服务和REST API获取市场数据、新闻、图表、SEC文件、基础数据、技术数据、研究。

  • 市场数据

    • yfinance
    • OpenBB.通过OpenBB平台API,我们可以通过统一的API调用几乎任何市场数据REST API。
  • 行情走势 -工具通过以下方式获得10-K项1 sec_downloader 并用以下方式解析它 sec_parser.

  • 技术分析 -计算一些技术指标 pandas_ta & TA-Lib.

  • 交互式绘图 -用plotly做一个情节

  • 新闻与社会情绪 -Reddit抓取工具。在启动时,我们启动一个浏览器上下文,并在会话期间保持其打开状态。通过将浏览器指向您的个人资料,您可以访问已保存的凭据。然后,您可以打开任何URL,并通过提示LLM生成相应的工具调用来抓取链接、文本或完整的HTML。


快速开始

# 1. Clone and enter the project (or fork and clone your own if you want to commit changes)
$ git clone https://github.com/druce/MCP.git
$ cd MCP

# 2. Create & activate a virtualenv (recommended)
$ python -m venv .venv
$ source .venv/bin/activate

# 3. Install python dependencies
$ pip install -r requirements.txt

# 4. Install Playwright browsers (once)
$ playwright install

# 5. Copy environment template & add your keys
$ cp dotenv.txt .env  # then edit as needed

# 6. Launch and test the server
$ LOGLEVEL=DEBUG mcp dev server.py
# click to the link in the terminal to open the test page, connect, view tools, and then test them individually

# 7. Use the server in your MCP client of choice. For Claude Desktop, edit the provided claude_desktop_config.json file and move it to the proper location for your platform (macOS, Windows).
https://claude.ai/download
https://modelcontextprotocol.io/quickstart/user

# 8. For additional optional market data MCP servers install these repos
Wikipedia MCP (no API key required)
pip install wikipedia-mcp

Filesystem MCP (use local files, no API key required)
git clone https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem

Yahoo Finance MCP (no API key required)
git clone https://github.com/Alex2Yang97/yahoo-finance-mcp.git

FMP MCP (API key required -  https://site.financialmodelingprep.com/developer/docs/stable )
git clone https://github.com/cdtait/fmp-mcp-server

Alpha Vantage MCP (API key required - https://www.alphavantage.co/documentation/)
git clone https://github.com/calvernaz/alphavantage.git
# see alphavantage.patches for edits to alphavantage/src/alphavantage_mcp_server/server.py

Brave Search MCP (API key required https://brave.com/search/api/ )
npm install -g @modelcontextprotocol/server-brave-search

Perplexity Ask MCP (API key, Docker required)
Follow setup instructions here:
https://github.com/ppl-ai/modelcontextprotocol/tree/main


项目结构

MCP/
├── claude_desktop_config.json # Configuration for Claude Desktop
├── dotenv.txt             # Secrets / Environment variables
├── README.md              # This file
├── server.py              # FastMCP server, launched by mcp dev or Claude desktop or other MCP client
├── requirements.txt       # Python dependencies
├── sources.yaml           # Data-source configuration used by server
├── Market Data.ipynb      # Jupyter notebook to fetch market data
├── TearSheet.ipynb        # Jupyter notebook to do basic analysis