Merge c6d5ddc7a6 into 13b826a31d
This commit is contained in:
commit
f34380e5c6
|
|
@ -0,0 +1,131 @@
|
||||||
|
---
|
||||||
|
description: 如何部署 TradingAgents 项目
|
||||||
|
---
|
||||||
|
|
||||||
|
# TradingAgents 部署工作流
|
||||||
|
|
||||||
|
本工作流描述如何从零开始部署 TradingAgents 多智能体交易框架。
|
||||||
|
|
||||||
|
## 前置条件
|
||||||
|
|
||||||
|
- 已安装 Conda
|
||||||
|
- 已安装 Git
|
||||||
|
- 有 OpenAI API 密钥
|
||||||
|
- 有 Alpha Vantage API 密钥(免费获取:https://www.alphavantage.co/support/#api-key)
|
||||||
|
|
||||||
|
## 部署步骤
|
||||||
|
|
||||||
|
### 1. 克隆项目(如果还未克隆)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/TauricResearch/TradingAgents.git
|
||||||
|
cd TradingAgents
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 创建 Conda 虚拟环境
|
||||||
|
|
||||||
|
// turbo
|
||||||
|
```bash
|
||||||
|
conda create -n tradingagents python=3.13 -y
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 激活环境并安装依赖
|
||||||
|
|
||||||
|
```bash
|
||||||
|
conda activate tradingagents
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 配置 API 密钥
|
||||||
|
|
||||||
|
复制示例环境文件:
|
||||||
|
python -m cli.main
|
||||||
|
```
|
||||||
|
|
||||||
|
这将启动一个交互式界面,你可以选择:
|
||||||
|
- 股票代码(ticker)
|
||||||
|
- 日期
|
||||||
|
- LLM 模型
|
||||||
|
- 研究深度等参数
|
||||||
|
|
||||||
|
#### 方式 2: 使用 Python 代码
|
||||||
|
|
||||||
|
创建测试脚本或运行 `main.py`:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from tradingagents.graph.trading_graph import TradingAgentsGraph
|
||||||
|
from tradingagents.default_config import DEFAULT_CONFIG
|
||||||
|
|
||||||
|
ta = TradingAgentsGraph(debug=True, config=DEFAULT_CONFIG.copy())
|
||||||
|
_, decision = ta.propagate("NVDA", "2024-05-10")
|
||||||
|
print(decision)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. 自定义配置(可选)
|
||||||
|
|
||||||
|
你可以修改默认配置来使用不同的 LLM 模型或数据源:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from tradingagents.default_config import DEFAULT_CONFIG
|
||||||
|
|
||||||
|
config = DEFAULT_CONFIG.copy()
|
||||||
|
config["deep_think_llm"] = "gpt-4o-mini" # 节省成本
|
||||||
|
config["quick_think_llm"] = "gpt-4o-mini"
|
||||||
|
config["max_debate_rounds"] = 1
|
||||||
|
|
||||||
|
# 配置数据供应商
|
||||||
|
config["data_vendors"] = {
|
||||||
|
"core_stock_apis": "yfinance",
|
||||||
|
"technical_indicators": "yfinance",
|
||||||
|
"fundamental_data": "alpha_vantage",
|
||||||
|
"news_data": "alpha_vantage",
|
||||||
|
}
|
||||||
|
|
||||||
|
ta = TradingAgentsGraph(debug=True, config=config)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 重要提示
|
||||||
|
|
||||||
|
⚠️ **成本控制**: 该框架会进行大量 API 调用。测试时建议使用 `gpt-4o-mini` 等较便宜的模型。
|
||||||
|
|
||||||
|
⚠️ **免责声明**: TradingAgents 仅用于研究目的,不构成财务、投资或交易建议。
|
||||||
|
|
||||||
|
⚠️ **API 限制**: Alpha Vantage 免费版有速率限制。TradingAgents 用户可获得提升的限制(每分钟 60 次请求,无每日限制)。
|
||||||
|
|
||||||
|
## 验证部署
|
||||||
|
|
||||||
|
运行以下命令验证环境配置正确:
|
||||||
|
|
||||||
|
// turbo
|
||||||
|
```bash
|
||||||
|
python test.py
|
||||||
|
```
|
||||||
|
|
||||||
|
或者运行一个简单的测试:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -c "from tradingagents.graph.trading_graph import TradingAgentsGraph; print('部署成功!')"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 故障排除
|
||||||
|
|
||||||
|
### 问题: 缺少 API 密钥
|
||||||
|
**解决方案**: 确保 `.env` 文件存在且包含有效的 API 密钥,或设置环境变量。
|
||||||
|
|
||||||
|
### 问题: 依赖安装失败
|
||||||
|
**解决方案**:
|
||||||
|
- 确保使用 Python 3.13
|
||||||
|
- 尝试升级 pip: `pip install --upgrade pip`
|
||||||
|
- 逐个安装依赖以识别问题包
|
||||||
|
|
||||||
|
### 问题: Alpha Vantage 速率限制
|
||||||
|
**解决方案**:
|
||||||
|
- 等待一分钟后重试
|
||||||
|
- 考虑升级到 Alpha Vantage Premium
|
||||||
|
- 或在配置中切换到其他数据源
|
||||||
|
|
||||||
|
## 下一步
|
||||||
|
|
||||||
|
- 查看 `tradingagents/default_config.py` 了解所有可配置选项
|
||||||
|
- 阅读项目文档了解多智能体架构
|
||||||
|
- 加入 Discord 社区: https://discord.com/invite/hk9PGKShPK
|
||||||
|
|
@ -0,0 +1,138 @@
|
||||||
|
# DeepSeek API 配置指南
|
||||||
|
|
||||||
|
## 📋 配置步骤
|
||||||
|
|
||||||
|
### 1. 获取 DeepSeek API 密钥
|
||||||
|
|
||||||
|
访问 DeepSeek 官网获取 API 密钥:
|
||||||
|
- 网址: https://platform.deepseek.com/
|
||||||
|
- 注册并登录账户
|
||||||
|
- 在 API Keys 页面创建新的 API 密钥
|
||||||
|
|
||||||
|
### 2. 配置环境变量
|
||||||
|
|
||||||
|
编辑项目根目录下的 `.env` 文件,填入您的 API 密钥:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# DeepSeek API 密钥(使用 OPENAI_API_KEY 变量名,因为 DeepSeek 兼容 OpenAI SDK)
|
||||||
|
OPENAI_API_KEY=your_deepseek_api_key_here
|
||||||
|
|
||||||
|
# Alpha Vantage API 密钥(用于获取股票数据)
|
||||||
|
ALPHA_VANTAGE_API_KEY=your_alpha_vantage_api_key_here
|
||||||
|
```
|
||||||
|
|
||||||
|
**重要提示**:
|
||||||
|
- DeepSeek API 使用 `OPENAI_API_KEY` 作为环境变量名
|
||||||
|
- 这是因为 DeepSeek 使用 OpenAI 兼容的 API 格式
|
||||||
|
- 不要将其与 OpenAI 的 API 密钥混淆
|
||||||
|
|
||||||
|
### 3. 验证配置
|
||||||
|
|
||||||
|
运行测试脚本验证 DeepSeek API 是否配置正确:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
conda activate tradingagents
|
||||||
|
python test_deepseek.py
|
||||||
|
```
|
||||||
|
|
||||||
|
如果看到 "✅ DeepSeek API 配置正确",说明配置成功!
|
||||||
|
|
||||||
|
## 🚀 运行 TradingAgents
|
||||||
|
|
||||||
|
### 使用 Python 脚本
|
||||||
|
|
||||||
|
已经为您配置好了 `main.py`,直接运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
conda activate tradingagents
|
||||||
|
python main.py
|
||||||
|
```
|
||||||
|
|
||||||
|
### 使用 CLI 界面
|
||||||
|
|
||||||
|
```bash
|
||||||
|
conda activate tradingagents
|
||||||
|
python -m cli.main
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 DeepSeek 模型说明
|
||||||
|
|
||||||
|
项目已配置使用以下 DeepSeek 模型:
|
||||||
|
|
||||||
|
- **deepseek-reasoner**: 深度思考模型(思考模式)
|
||||||
|
- 用于复杂的分析和决策任务
|
||||||
|
- 对应 `deep_think_llm` 配置
|
||||||
|
|
||||||
|
- **deepseek-chat**: 快速对话模型(非思考模式)
|
||||||
|
- 用于快速响应和简单任务
|
||||||
|
- 对应 `quick_think_llm` 配置
|
||||||
|
|
||||||
|
## 💰 成本优化建议
|
||||||
|
|
||||||
|
DeepSeek API 的定价比 OpenAI 更实惠,但仍建议:
|
||||||
|
|
||||||
|
1. **测试时使用较少的辩论轮次**
|
||||||
|
- 当前配置: `max_debate_rounds = 1`
|
||||||
|
- 可以根据需要调整
|
||||||
|
|
||||||
|
2. **监控 API 使用量**
|
||||||
|
- 在 DeepSeek 控制台查看使用情况
|
||||||
|
- 设置使用限额避免超支
|
||||||
|
|
||||||
|
3. **使用缓存**
|
||||||
|
- 项目会缓存股票数据
|
||||||
|
- 避免重复调用相同数据
|
||||||
|
|
||||||
|
## 📊 配置文件说明
|
||||||
|
|
||||||
|
主要配置在 `main.py` 中:
|
||||||
|
|
||||||
|
```python
|
||||||
|
config = DEFAULT_CONFIG.copy()
|
||||||
|
|
||||||
|
# DeepSeek API 配置
|
||||||
|
config["llm_provider"] = "openai" # 使用 OpenAI 兼容接口
|
||||||
|
config["backend_url"] = "https://api.deepseek.com" # DeepSeek API 端点
|
||||||
|
config["deep_think_llm"] = "deepseek-reasoner" # 思考模式
|
||||||
|
config["quick_think_llm"] = "deepseek-chat" # 非思考模式
|
||||||
|
config["max_debate_rounds"] = 1 # 辩论轮次
|
||||||
|
|
||||||
|
# 数据源配置
|
||||||
|
config["data_vendors"] = {
|
||||||
|
"core_stock_apis": "yfinance",
|
||||||
|
"technical_indicators": "yfinance",
|
||||||
|
"fundamental_data": "alpha_vantage",
|
||||||
|
"news_data": "alpha_vantage",
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## ❓ 常见问题
|
||||||
|
|
||||||
|
### Q: 为什么使用 OPENAI_API_KEY 而不是 DEEPSEEK_API_KEY?
|
||||||
|
|
||||||
|
A: DeepSeek API 使用 OpenAI 兼容的格式,langchain-openai 库默认读取 `OPENAI_API_KEY` 环境变量。通过设置 `base_url="https://api.deepseek.com"`,我们将请求重定向到 DeepSeek 的服务器。
|
||||||
|
|
||||||
|
### Q: 可以同时使用 OpenAI 和 DeepSeek 吗?
|
||||||
|
|
||||||
|
A: 可以,但需要修改代码来支持不同的 API 密钥。当前配置只支持一个 LLM 提供商。
|
||||||
|
|
||||||
|
### Q: Alpha Vantage API 是必需的吗?
|
||||||
|
|
||||||
|
A: 是的,用于获取股票基本面数据和新闻。您可以免费获取 API 密钥: https://www.alphavantage.co/support/#api-key
|
||||||
|
|
||||||
|
### Q: 如何切换回 OpenAI?
|
||||||
|
|
||||||
|
A: 修改 `main.py` 中的配置:
|
||||||
|
```python
|
||||||
|
config["backend_url"] = "https://api.openai.com/v1"
|
||||||
|
config["deep_think_llm"] = "gpt-4o"
|
||||||
|
config["quick_think_llm"] = "gpt-4o-mini"
|
||||||
|
```
|
||||||
|
并在 `.env` 中使用 OpenAI 的 API 密钥。
|
||||||
|
|
||||||
|
## 🔗 相关链接
|
||||||
|
|
||||||
|
- DeepSeek 平台: https://platform.deepseek.com/
|
||||||
|
- DeepSeek API 文档: https://platform.deepseek.com/api-docs/
|
||||||
|
- Alpha Vantage: https://www.alphavantage.co/
|
||||||
|
- TradingAgents GitHub: https://github.com/TauricResearch/TradingAgents
|
||||||
|
|
@ -0,0 +1,198 @@
|
||||||
|
# 🎉 TradingAgents 部署成功报告
|
||||||
|
|
||||||
|
## ✅ 部署状态:成功
|
||||||
|
|
||||||
|
**部署时间**: 2025-11-20
|
||||||
|
**LLM 提供商**: DeepSeek API
|
||||||
|
**测试状态**: ✅ 通过
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 完成的配置
|
||||||
|
|
||||||
|
### 1. 环境设置
|
||||||
|
- ✅ 创建 Conda 虚拟环境 `tradingagents` (Python 3.13)
|
||||||
|
- ✅ 安装所有依赖包(254个包)
|
||||||
|
- ✅ 配置环境变量 (.env 文件)
|
||||||
|
|
||||||
|
### 2. API 配置
|
||||||
|
- ✅ DeepSeek API 密钥配置
|
||||||
|
- ✅ Alpha Vantage API 密钥配置
|
||||||
|
- ✅ API 连接测试通过
|
||||||
|
|
||||||
|
### 3. 代码修改
|
||||||
|
- ✅ 修改 `main.py` 以支持 DeepSeek API
|
||||||
|
- ✅ 修改 `memory.py` 以兼容 DeepSeek(禁用 embedding 功能)
|
||||||
|
- ✅ 创建测试脚本 `test_simple.py`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 测试结果
|
||||||
|
|
||||||
|
### 测试案例
|
||||||
|
- **股票代码**: NVDA (英伟达)
|
||||||
|
- **分析日期**: 2024-05-10
|
||||||
|
- **分析师**: 市场技术分析师
|
||||||
|
|
||||||
|
### 分析结果
|
||||||
|
```
|
||||||
|
交易决策: SELL
|
||||||
|
```
|
||||||
|
|
||||||
|
**分析依据**:
|
||||||
|
- 技术指标分析完成
|
||||||
|
- 多智能体辩论完成
|
||||||
|
- 风险评估完成
|
||||||
|
- 最终决策: 卖出建议
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 使用的配置
|
||||||
|
|
||||||
|
### DeepSeek API 设置
|
||||||
|
```python
|
||||||
|
config["llm_provider"] = "openai"
|
||||||
|
config["backend_url"] = "https://api.deepseek.com"
|
||||||
|
config["deep_think_llm"] = "deepseek-reasoner" # 思考模式
|
||||||
|
config["quick_think_llm"] = "deepseek-chat" # 非思考模式
|
||||||
|
```
|
||||||
|
|
||||||
|
### 数据源配置
|
||||||
|
```python
|
||||||
|
config["data_vendors"] = {
|
||||||
|
"core_stock_apis": "yfinance",
|
||||||
|
"technical_indicators": "yfinance",
|
||||||
|
"fundamental_data": "yfinance",
|
||||||
|
"news_data": "yfinance",
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚠️ 已知限制
|
||||||
|
|
||||||
|
### 1. Embedding 功能已禁用
|
||||||
|
- **原因**: DeepSeek API 不提供 embedding API
|
||||||
|
- **影响**: 记忆功能(Memory)使用虚拟 embeddings
|
||||||
|
- **解决方案**: 系统仍可正常运行,但历史记忆匹配功能受限
|
||||||
|
|
||||||
|
### 2. 全球新闻分析
|
||||||
|
- **状态**: 在某些情况下可能失败
|
||||||
|
- **解决方案**: 使用 yfinance 作为数据源,或跳过新闻分析师
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 运行方式
|
||||||
|
|
||||||
|
### 方式 1: 简化测试(推荐)
|
||||||
|
```bash
|
||||||
|
conda activate tradingagents
|
||||||
|
python test_simple.py
|
||||||
|
```
|
||||||
|
|
||||||
|
### 方式 2: 完整运行
|
||||||
|
```bash
|
||||||
|
conda activate tradingagents
|
||||||
|
python main.py
|
||||||
|
```
|
||||||
|
|
||||||
|
### 方式 3: CLI 界面
|
||||||
|
```bash
|
||||||
|
conda activate tradingagents
|
||||||
|
python -m cli.main
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 下一步建议
|
||||||
|
|
||||||
|
### 1. 测试更多股票
|
||||||
|
修改 `test_simple.py` 中的股票代码和日期:
|
||||||
|
```python
|
||||||
|
_, decision = ta.propagate("AAPL", "2024-05-10") # 测试苹果股票
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 启用更多分析师
|
||||||
|
在 `test_simple.py` 中修改:
|
||||||
|
```python
|
||||||
|
selected_analysts = ["market", "fundamentals"] # 添加基本面分析
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 调整辩论轮次
|
||||||
|
```python
|
||||||
|
config["max_debate_rounds"] = 2 # 增加辩论深度
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 成本优化
|
||||||
|
- 监控 DeepSeek API 使用量
|
||||||
|
- 使用 `deepseek-chat` 替代 `deepseek-reasoner` 以降低成本
|
||||||
|
- 缓存常用数据
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 性能指标
|
||||||
|
|
||||||
|
### API 调用
|
||||||
|
- ✅ DeepSeek API: 正常
|
||||||
|
- ✅ Alpha Vantage API: 正常
|
||||||
|
- ✅ YFinance: 正常
|
||||||
|
|
||||||
|
### 执行时间
|
||||||
|
- 单次分析: ~2-3 分钟(取决于网络和 API 响应)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔗 相关文件
|
||||||
|
|
||||||
|
- `DEEPSEEK_CONFIG.md` - DeepSeek 配置详细指南
|
||||||
|
- `test_deepseek.py` - API 连接测试脚本
|
||||||
|
- `test_simple.py` - 简化版交易分析测试
|
||||||
|
- `main.py` - 主程序(已配置 DeepSeek)
|
||||||
|
- `.env` - 环境变量配置
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 💡 故障排除
|
||||||
|
|
||||||
|
### 问题 1: API 密钥错误
|
||||||
|
**解决方案**: 检查 `.env` 文件中的 API 密钥是否正确
|
||||||
|
|
||||||
|
### 问题 2: 网络连接失败
|
||||||
|
**解决方案**:
|
||||||
|
- 检查网络连接
|
||||||
|
- 确认 DeepSeek API 服务可用
|
||||||
|
- 尝试使用代理
|
||||||
|
|
||||||
|
### 问题 3: 数据获取失败
|
||||||
|
**解决方案**:
|
||||||
|
- 检查 Alpha Vantage API 配额
|
||||||
|
- 切换到 yfinance 数据源
|
||||||
|
- 检查股票代码是否正确
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📞 支持资源
|
||||||
|
|
||||||
|
- **TradingAgents GitHub**: https://github.com/TauricResearch/TradingAgents
|
||||||
|
- **DeepSeek 平台**: https://platform.deepseek.com/
|
||||||
|
- **Alpha Vantage**: https://www.alphavantage.co/
|
||||||
|
- **Discord 社区**: https://discord.com/invite/hk9PGKShPK
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✨ 总结
|
||||||
|
|
||||||
|
TradingAgents 已成功部署并配置为使用 DeepSeek API。系统能够:
|
||||||
|
|
||||||
|
1. ✅ 获取股票数据
|
||||||
|
2. ✅ 进行技术分析
|
||||||
|
3. ✅ 执行多智能体辩论
|
||||||
|
4. ✅ 生成交易决策
|
||||||
|
|
||||||
|
**状态**: 🟢 生产就绪
|
||||||
|
|
||||||
|
**建议**: 在实际交易前,建议进行更多回测和验证。本系统仅供研究和教育目的使用。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*最后更新: 2025-11-20*
|
||||||
|
|
@ -0,0 +1,243 @@
|
||||||
|
# 🚀 TradingAgents 快速开始指南
|
||||||
|
|
||||||
|
## ✅ 部署已完成!
|
||||||
|
|
||||||
|
恭喜!TradingAgents 已成功配置为使用 DeepSeek API。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 快速运行
|
||||||
|
|
||||||
|
### 1. 激活环境
|
||||||
|
```bash
|
||||||
|
conda activate tradingagents
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 运行测试(推荐新手)
|
||||||
|
```bash
|
||||||
|
python test_simple.py
|
||||||
|
```
|
||||||
|
|
||||||
|
这将分析 NVDA(英伟达)股票并给出交易建议。
|
||||||
|
|
||||||
|
### 3. 运行完整版本
|
||||||
|
```bash
|
||||||
|
python main.py
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 使用 CLI 界面
|
||||||
|
```bash
|
||||||
|
python -m cli.main
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 自定义分析
|
||||||
|
|
||||||
|
### 修改股票和日期
|
||||||
|
|
||||||
|
编辑 `test_simple.py`,找到这一行:
|
||||||
|
```python
|
||||||
|
_, decision = ta.propagate("NVDA", "2024-05-10")
|
||||||
|
```
|
||||||
|
|
||||||
|
改为:
|
||||||
|
```python
|
||||||
|
_, decision = ta.propagate("AAPL", "2024-06-15") # 分析苹果股票
|
||||||
|
```
|
||||||
|
|
||||||
|
### 启用更多分析师
|
||||||
|
|
||||||
|
在 `test_simple.py` 中找到:
|
||||||
|
```python
|
||||||
|
selected_analysts = ["market"] # 只有市场分析师
|
||||||
|
```
|
||||||
|
|
||||||
|
改为:
|
||||||
|
```python
|
||||||
|
selected_analysts = ["market", "fundamentals"] # 添加基本面分析
|
||||||
|
# 或
|
||||||
|
selected_analysts = ["market", "social", "fundamentals"] # 添加社交媒体分析
|
||||||
|
```
|
||||||
|
|
||||||
|
**注意**: 更多分析师 = 更多 API 调用 = 更高成本
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 💰 成本控制
|
||||||
|
|
||||||
|
### 使用更便宜的模型
|
||||||
|
|
||||||
|
编辑 `main.py` 或 `test_simple.py`:
|
||||||
|
```python
|
||||||
|
config["deep_think_llm"] = "deepseek-chat" # 改用非思考模式
|
||||||
|
config["quick_think_llm"] = "deepseek-chat"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 减少辩论轮次
|
||||||
|
```python
|
||||||
|
config["max_debate_rounds"] = 1 # 默认值,可以保持
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 理解输出
|
||||||
|
|
||||||
|
### 交易决策类型
|
||||||
|
- **BUY**: 买入建议
|
||||||
|
- **SELL**: 卖出建议
|
||||||
|
- **HOLD**: 持有建议
|
||||||
|
|
||||||
|
### 分析流程
|
||||||
|
1. 📈 **数据收集**: 获取股票价格、技术指标
|
||||||
|
2. 🤖 **分析师分析**: 各专业分析师独立分析
|
||||||
|
3. 💬 **多方辩论**: 看涨/看跌研究员辩论
|
||||||
|
4. 📝 **交易员决策**: 基于辩论结果制定计划
|
||||||
|
5. ⚖️ **风险评估**: 风险管理团队评估
|
||||||
|
6. ✅ **最终决策**: 投资组合经理批准
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 配置文件说明
|
||||||
|
|
||||||
|
### 当前配置(DeepSeek)
|
||||||
|
|
||||||
|
**LLM 设置**:
|
||||||
|
- Provider: DeepSeek API
|
||||||
|
- Deep Think: `deepseek-reasoner` (思考模式)
|
||||||
|
- Quick Think: `deepseek-chat` (快速模式)
|
||||||
|
|
||||||
|
**数据源**:
|
||||||
|
- 股票数据: YFinance
|
||||||
|
- 技术指标: YFinance
|
||||||
|
- 基本面: YFinance
|
||||||
|
- 新闻: YFinance
|
||||||
|
|
||||||
|
### 切换回 OpenAI
|
||||||
|
|
||||||
|
如果想使用 OpenAI,修改配置:
|
||||||
|
```python
|
||||||
|
config["backend_url"] = "https://api.openai.com/v1"
|
||||||
|
config["deep_think_llm"] = "o1-mini"
|
||||||
|
config["quick_think_llm"] = "gpt-4o-mini"
|
||||||
|
```
|
||||||
|
|
||||||
|
并在 `.env` 中使用 OpenAI API 密钥。
|
||||||
|
|
||||||
|
### 使用 OpenRouter
|
||||||
|
|
||||||
|
如果想使用 OpenRouter,修改配置:
|
||||||
|
```python
|
||||||
|
config["backend_url"] = "https://openrouter.ai/api/v1"
|
||||||
|
config["deep_think_llm"] = "openai/gpt-4o-mini" # 或其他 OpenRouter 模型
|
||||||
|
config["quick_think_llm"] = "openai/gpt-4o-mini"
|
||||||
|
```
|
||||||
|
|
||||||
|
并在 `.env` 中设置 `OPENAI_API_KEY` 为您的 OpenRouter 密钥。
|
||||||
|
**注意**: 系统会自动检测 OpenRouter 并禁用 embeddings 功能(避免 `AttributeError`)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚠️ 重要提示
|
||||||
|
|
||||||
|
### 1. 记忆功能已禁用
|
||||||
|
- DeepSeek 不支持 embeddings API
|
||||||
|
- 系统使用虚拟 embeddings
|
||||||
|
- 不影响核心分析功能
|
||||||
|
|
||||||
|
### 2. 仅供研究使用
|
||||||
|
- **不构成投资建议**
|
||||||
|
- 请勿直接用于实际交易
|
||||||
|
- 建议进行充分回测
|
||||||
|
|
||||||
|
### 3. API 配额管理
|
||||||
|
- 监控 DeepSeek API 使用量
|
||||||
|
- Alpha Vantage 免费版: 60次/分钟
|
||||||
|
- 避免短时间内大量请求
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 进阶功能
|
||||||
|
|
||||||
|
### 批量分析多个股票
|
||||||
|
|
||||||
|
创建新脚本 `batch_analysis.py`:
|
||||||
|
```python
|
||||||
|
from tradingagents.graph.trading_graph import TradingAgentsGraph
|
||||||
|
from tradingagents.default_config import DEFAULT_CONFIG
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
# 配置
|
||||||
|
config = DEFAULT_CONFIG.copy()
|
||||||
|
config["llm_provider"] = "openai"
|
||||||
|
config["backend_url"] = "https://api.deepseek.com"
|
||||||
|
config["deep_think_llm"] = "deepseek-chat"
|
||||||
|
config["quick_think_llm"] = "deepseek-chat"
|
||||||
|
|
||||||
|
ta = TradingAgentsGraph(debug=False, config=config, selected_analysts=["market"])
|
||||||
|
|
||||||
|
# 批量分析
|
||||||
|
stocks = ["NVDA", "AAPL", "MSFT", "GOOGL"]
|
||||||
|
date = "2024-05-10"
|
||||||
|
|
||||||
|
for stock in stocks:
|
||||||
|
print(f"\n分析 {stock}...")
|
||||||
|
_, decision = ta.propagate(stock, date)
|
||||||
|
print(f"{stock}: {decision}")
|
||||||
|
```
|
||||||
|
|
||||||
|
### 回测功能
|
||||||
|
|
||||||
|
查看 `main.py` 中的反思功能:
|
||||||
|
```python
|
||||||
|
# 在交易后反思和学习
|
||||||
|
ta.reflect_and_remember(returns_losses=1000) # 传入收益/损失
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🐛 常见问题
|
||||||
|
|
||||||
|
### Q: 运行很慢怎么办?
|
||||||
|
A:
|
||||||
|
- 使用 `deepseek-chat` 替代 `deepseek-reasoner`
|
||||||
|
- 减少分析师数量
|
||||||
|
- 检查网络连接
|
||||||
|
|
||||||
|
### Q: 出现 API 错误?
|
||||||
|
A:
|
||||||
|
- 检查 API 密钥是否正确
|
||||||
|
- 确认 API 配额未用完
|
||||||
|
- 查看错误信息详情
|
||||||
|
|
||||||
|
### Q: 如何保存分析结果?
|
||||||
|
A:
|
||||||
|
结果自动保存在 `eval_results/{股票代码}/` 目录下
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📞 获取帮助
|
||||||
|
|
||||||
|
- **配置指南**: 查看 `DEEPSEEK_CONFIG.md`
|
||||||
|
- **部署报告**: 查看 `DEPLOYMENT_SUCCESS.md`
|
||||||
|
- **GitHub Issues**: https://github.com/TauricResearch/TradingAgents/issues
|
||||||
|
- **Discord**: https://discord.com/invite/hk9PGKShPK
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎉 开始使用!
|
||||||
|
|
||||||
|
现在您可以开始使用 TradingAgents 进行股票分析了!
|
||||||
|
|
||||||
|
```bash
|
||||||
|
conda activate tradingagents
|
||||||
|
python test_simple.py
|
||||||
|
```
|
||||||
|
|
||||||
|
祝您分析愉快!📈
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*最后更新: 2025-11-20*
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
"""
|
||||||
|
简化版 TradingAgents 测试
|
||||||
|
跳过可能有问题的全球新闻分析,只测试核心功能
|
||||||
|
"""
|
||||||
|
|
||||||
|
from tradingagents.graph.trading_graph import TradingAgentsGraph
|
||||||
|
from tradingagents.default_config import DEFAULT_CONFIG
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
# Load environment variables from .env file
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
# Create a custom config for DeepSeek API
|
||||||
|
config = DEFAULT_CONFIG.copy()
|
||||||
|
|
||||||
|
# Configure DeepSeek API
|
||||||
|
config["llm_provider"] = "openai" # DeepSeek uses OpenAI-compatible API
|
||||||
|
config["backend_url"] = "https://api.deepseek.com" # DeepSeek API endpoint
|
||||||
|
config["deep_think_llm"] = "deepseek-reasoner" # DeepSeek reasoning model (思考模式)
|
||||||
|
config["quick_think_llm"] = "deepseek-chat" # DeepSeek chat model (非思考模式)
|
||||||
|
config["max_debate_rounds"] = 1 # Debate rounds
|
||||||
|
|
||||||
|
# Configure data vendors - 使用 yfinance 作为主要数据源
|
||||||
|
config["data_vendors"] = {
|
||||||
|
"core_stock_apis": "yfinance", # Options: yfinance, alpha_vantage, local
|
||||||
|
"technical_indicators": "yfinance", # Options: yfinance, alpha_vantage, local
|
||||||
|
"fundamental_data": "yfinance", # 改用 yfinance 避免 API 限制
|
||||||
|
"news_data": "yfinance", # 改用 yfinance 避免 API 限制
|
||||||
|
}
|
||||||
|
|
||||||
|
print("=" * 60)
|
||||||
|
print("初始化 TradingAgents (使用 DeepSeek API)")
|
||||||
|
print("=" * 60)
|
||||||
|
print(f"LLM Provider: {config['llm_provider']}")
|
||||||
|
print(f"Backend URL: {config['backend_url']}")
|
||||||
|
print(f"Deep Think Model: {config['deep_think_llm']}")
|
||||||
|
print(f"Quick Think Model: {config['quick_think_llm']}")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
# 只使用市场分析师,跳过新闻分析以避免 API 问题
|
||||||
|
# selected_analysts = ["market", "social", "fundamentals"] # 跳过 "news"
|
||||||
|
selected_analysts = ["market"] # 先只测试市场分析
|
||||||
|
|
||||||
|
print(f"\n选择的分析师: {selected_analysts}")
|
||||||
|
print("\n开始初始化 TradingAgents Graph...")
|
||||||
|
|
||||||
|
# Initialize with custom config
|
||||||
|
ta = TradingAgentsGraph(
|
||||||
|
debug=True,
|
||||||
|
config=config,
|
||||||
|
selected_analysts=selected_analysts
|
||||||
|
)
|
||||||
|
|
||||||
|
print("✓ TradingAgents Graph 初始化成功!")
|
||||||
|
print("\n开始分析 NVDA (英伟达) 在 2024-05-10 的交易决策...")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
# forward propagate
|
||||||
|
try:
|
||||||
|
_, decision = ta.propagate("NVDA", "2024-05-10")
|
||||||
|
print("\n" + "=" * 60)
|
||||||
|
print("✅ 分析完成!")
|
||||||
|
print("=" * 60)
|
||||||
|
print(f"交易决策: {decision}")
|
||||||
|
print("=" * 60)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\n❌ 分析过程中出现错误: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
@ -5,16 +5,26 @@ from openai import OpenAI
|
||||||
|
|
||||||
class FinancialSituationMemory:
|
class FinancialSituationMemory:
|
||||||
def __init__(self, name, config):
|
def __init__(self, name, config):
|
||||||
if config["backend_url"] == "http://localhost:11434/v1":
|
# Check if using DeepSeek API (which doesn't support embeddings)
|
||||||
|
self.use_embeddings = True
|
||||||
|
if "deepseek" in config["backend_url"].lower() or "openrouter" in config["backend_url"].lower():
|
||||||
|
self.use_embeddings = False
|
||||||
|
print(f"⚠️ API (DeepSeek/OpenRouter) 不支持 embeddings,{name} 记忆功能已禁用")
|
||||||
|
elif config["backend_url"] == "http://localhost:11434/v1":
|
||||||
self.embedding = "nomic-embed-text"
|
self.embedding = "nomic-embed-text"
|
||||||
else:
|
else:
|
||||||
self.embedding = "text-embedding-3-small"
|
self.embedding = "text-embedding-3-small"
|
||||||
self.client = OpenAI(base_url=config["backend_url"])
|
|
||||||
|
if self.use_embeddings:
|
||||||
|
self.client = OpenAI(base_url=config["backend_url"])
|
||||||
self.chroma_client = chromadb.Client(Settings(allow_reset=True))
|
self.chroma_client = chromadb.Client(Settings(allow_reset=True))
|
||||||
self.situation_collection = self.chroma_client.create_collection(name=name)
|
self.situation_collection = self.chroma_client.create_collection(name=name)
|
||||||
|
|
||||||
def get_embedding(self, text):
|
def get_embedding(self, text):
|
||||||
"""Get OpenAI embedding for a text"""
|
"""Get OpenAI embedding for a text"""
|
||||||
|
if not self.use_embeddings:
|
||||||
|
# Return a dummy embedding if embeddings are disabled
|
||||||
|
return [0.0] * 1536 # Standard embedding size
|
||||||
|
|
||||||
response = self.client.embeddings.create(
|
response = self.client.embeddings.create(
|
||||||
model=self.embedding, input=text
|
model=self.embedding, input=text
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue