本專案基於 virattt/ai-hedge-fund 和 KRSHH/ritadel,並進一步擴展,
提供 Web API 介面,可讓其他應用直接調用 AI 分析師的投資建議。
主要改動:
- ✅ 使用 Python 3.13,棄用 Poetry,改用 Pip 管理依賴
- ✅ 內建 Flask API 服務(預設運行於
6000端口) - ✅ 支援多種 LLM(GPT-4o、Claude 3、LLaMA3、Gemini)
- ✅ 支援金融數據 API(Alpha Vantage、StockData、Finnhub 等)
- ✅ 支援 Docker 部署,可直接
docker run啟動 API 服務 - ✅ 14 個專業投資分析師 AI Agent,涵蓋價值投資、成長投資、技術分析等多種策略
telegram bot
https://github.com/tbdavid2019/telegram-bot-stock2

git clone https://github.com/tbdavid2019/ai-hedge-fund-API.git
cd ai-hedge-fund-APIpython3 -m venv venv
source venv/bin/activate # Windows 則使用 venv\Scripts\activate
pip install --upgrade pip
pip install -r requirements.txt請在專案根目錄創建 .env 檔案,並填入 API Keys:
# LLM API Keys(至少設定一個)
OPENAI_API_KEY=your-openai-api-key
ANTHROPIC_API_KEY=your-anthropic-api-key
GROQ_API_KEY=your-groq-api-key
GEMINI_API_KEY=your-gemini-api-key
# 金融數據 API Keys(至少設定一個)
ALPHA_VANTAGE_API_KEY=your-alpha-vantage-key
STOCKDATA_API_KEY=your-stockdata-key
FINNHUB_API_KEY=your-finnhub-key
EODHD_API_KEY=your-eodhd-key
# Discord Webhook(可選,用於推送分析結果通知)
# 預設關閉,設為 true 啟用
DISCORD_WEBHOOK_ENABLED=false
DISCORD_WEBHOOK_URL=your-discord-webhook-url本專案支援將分析結果自動推送到 Discord 頻道(預設關閉):
- 在 Discord 頻道設定中建立 Webhook(Server Settings → Integrations → Webhooks)
- 在
.env檔案中設定:DISCORD_WEBHOOK_ENABLED=true DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/your-webhook-url
- 重新啟動服務,每次分析完成後結果會自動推送到指定的 Discord 頻道
- 📅 分析日期
- 📈 分析標的
- 🎯 投資決策(買入/賣出/持有)
- 💯 信心度
- 📊 各分析師信號摘要
python webui2.py --api預設 API 會運行於 http://localhost:6000
啟動服務後,可訪問 Swagger UI 查看完整 API 文檔:
- Swagger UI: http://localhost:6000/docs
- 健康檢查: http://localhost:6000/api/health
預建的 Docker 映像可直接從 Docker Hub 拉取:
docker pull tbdavid2019/ai-hedge-fund-api:latest
docker run --env-file .env -p 6000:6000 tbdavid2019/ai-hedge-fund-api:latest本專案內建 14 個專業 AI 投資分析師,每個分析師都基於真實投資大師的策略和哲學:
| 順序 | Key | 顯示名稱 | Agent 檔案 | 投資策略 |
|---|---|---|---|---|
| 0 | ben_graham |
Ben Graham | ben_graham.py |
價值投資之父,重視安全邊際、低本益比、穩健財務 |
| 1 | bill_ackman |
Bill Ackman | bill_ackman.py |
激進價值投資,專注優質企業、集中持股 |
| 3 | charlie_munger |
Charlie Munger | charlie_munger.py |
品質投資,尋找護城河、高 ROE、優秀管理層 |
| 5 | michael_burry |
Michael Burry | michael_burry.py |
深度價值投資,尋找被低估的資產淨值 |
| 6 | peter_lynch |
Peter Lynch | peter_lynch.py |
成長價值投資,重視 PEG Ratio、熟悉的企業 |
| 7 | phil_fisher |
Phil Fisher | phil_fisher.py |
成長潛力分析,重視研發、管理品質、產業前景 |
| 8 | warren_buffett |
Warren Buffett | warren_buffett.py |
長期價值投資,尋找優質企業、合理價格 |
| 順序 | Key | 顯示名稱 | Agent 檔案 | 投資策略 |
|---|---|---|---|---|
| 2 | cathie_wood |
Cathie Wood | cathie_wood.py |
顛覆式創新投資,聚焦 AI、電動車、基因科技 |
| 順序 | Key | 顯示名稱 | Agent 檔案 | 分析方式 |
|---|---|---|---|---|
| 4 | nancy_pelosi |
Nancy Pelosi | nancy_pelosi.py |
追蹤國會議員股票交易記錄 |
| 9 | wsb |
WallStreetBets | wsb_agent.py |
Reddit 社群情緒、散戶動能分析 |
| 10 | technical_analyst |
Technical Analyst | technicals.py |
技術分析:MA、RSI、MACD 等指標 |
| 11 | sentiment_analyst |
Sentiment Analyst | sentiment.py |
新聞情緒分析、市場氛圍評估 |
| 順序 | Key | 顯示名稱 | Agent 檔案 | 分析方式 |
|---|---|---|---|---|
| 12 | fundamentals_analyst |
Fundamentals Analyst | fundamentals.py |
深度財務報表分析 |
| 13 | valuation_analyst |
Valuation Analyst | valuation.py |
企業估值模型、DCF 分析 |
這些 Agent 在工作流中自動執行,不需要在 API 請求中指定:
portfolio_manager.py- 投資組合管理risk_manager.py- 風險管理與部位控制round_table.py- 綜合討論與決策整合
docker build -t ai-hedge-fund-api .docker run --env-file .env -p 6000:6000 ai-hedge-fund-apicurl -X POST "http://localhost:6000/api/analysis" \
-H "Content-Type: application/json" \
-d '{
"tickers": "tsla",
"selectedAnalysts": ["ben_graham"],
"modelName": "gpt-4o"
}'| 參數 | 類型 | 必填 | 說明 | 範例 |
|---|---|---|---|---|
tickers |
string | ✅ | 股票代碼(逗號分隔) | "AAPL,TSLA,NVDA" |
selectedAnalysts |
array | 要使用的分析師列表(空陣列=使用全部) | ["ben_graham", "warren_buffett"] |
|
modelName |
string | ✅ | LLM 模型名稱 | "gpt-4o", "claude-3-5-sonnet-20241022" |
startDate |
string | ❌ | 分析起始日期(預設:結束日期前 3 個月) | "2024-01-01" |
endDate |
string | ❌ | 分析結束日期(預設:今天) | "2024-12-31" |
initialCash |
number | ❌ | 初始現金(預設:100000) | 100000 |
系統會根據分析的標的物數量,自動調整每個標的物的投資上限比例:
| 標的物數量 | 每個標的物上限 | 說明 |
|---|---|---|
| 1 個 | 100% | 單一標的,可全倉投入 |
| 2 個 | 50% | 平均分配 |
| 3 個 | 33% | 平均分配 |
| 4 個 | 25% | 平均分配 |
| 5+ 個 | 20% | 分散風險 |
範例:
- 分析
TSLA一檔股票,初始現金 $100,000 → 最大可投入 $100,000 - 分析
TSLA,NVDA兩檔股票 → 每檔最大可投入 $50,000 - 分析
TSLA,NVDA,AAPL,GOOGL,AMZN五檔股票 → 每檔最大可投入 $20,000
你可以在請求中指定以下任意組合的分析師(或留空使用全部):
價值投資大師:
["ben_graham", "bill_ackman", "charlie_munger", "michael_burry", "peter_lynch", "phil_fisher", "warren_buffett"]成長與創新:
["cathie_wood"]技術與情緒分析:
["nancy_pelosi", "wsb", "technical_analyst", "sentiment_analyst"]基本面與估值:
["fundamentals_analyst", "valuation_analyst"]完整範例(使用多個分析師):
curl -X POST "http://localhost:6000/api/analysis" \
-H "Content-Type: application/json" \
-d '{
"tickers": "AAPL,NVDA",
"selectedAnalysts": ["warren_buffett", "peter_lynch", "technical_analyst"],
"modelName": "gpt-4o",
"startDate": "2024-09-01",
"endDate": "2024-11-21",
"initialCash": 50000
}'{
"analyst_signals": {
"ben_graham_agent": {
"tsla": {
"confidence": 80.0,
"reasoning": "Tesla's financial assessment reveals several weaknesses from a Graham perspective...",
"signal": "bearish"
}
},
"risk_management_agent": {
"tsla": {
"current_price": 236.25,
"reasoning": {
"available_cash": 100000.0,
"current_position": 0.0,
"portfolio_value": 100000.0,
"position_limit": 20000.0,
"remaining_limit": 20000.0
},
"remaining_position_limit": 20000.0
}
}
},
"decisions": {
"tsla": {
"action": "short",
"confidence": 80.0,
"quantity": 84,
"reasoning": "The analysis by the ben_graham_agent indicates a strong bearish signal..."
}
}
}This project extends virattt/ai-hedge-fund and KRSHH/ritadel,
providing a RESTful API for external applications to query AI-driven investment insights.
Major Improvements:
- ✅ Python 3.13 (Switched from Poetry to Pip)
- ✅ Built-in Flask API (default port:
6000) - ✅ Supports multiple LLMs (GPT-4o, Claude 3, LLaMA3, Gemini)
- ✅ Financial Data APIs (Alpha Vantage, StockData, Finnhub, etc.)
- ✅ Docker-ready, deploy via
docker run - ✅ 14 Professional AI Investment Analysts covering Value, Growth, Technical Analysis strategies
git clone https://github.com/tbdavid2019/ai-hedge-fund-API.git
cd ai-hedge-fund-APIpython3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txtOPENAI_API_KEY=your-openai-api-key
ANTHROPIC_API_KEY=your-anthropic-api-key
GROQ_API_KEY=your-groq-api-key
GEMINI_API_KEY=your-gemini-api-key
ALPHA_VANTAGE_API_KEY=your-alpha-vantage-key
STOCKDATA_API_KEY=your-stockdata-key
FINNHUB_API_KEY=your-finnhub-key
EODHD_API_KEY=your-eodhd-keypython webui2.py --api(Default API runs on http://localhost:6000)
This project includes 14 professional AI investment analysts, each based on real investment masters' strategies:
📊 Value Investing Masters: ben_graham, bill_ackman, charlie_munger, michael_burry, peter_lynch, phil_fisher, warren_buffett
🚀 Growth & Innovation: cathie_wood
📈 Technical & Sentiment: nancy_pelosi, wsb, technical_analyst, sentiment_analyst
📐 Fundamentals & Valuation: fundamentals_analyst, valuation_analyst
(See Chinese section above for detailed strategy descriptions)
docker build -t ai-hedge-fund-api .docker run --env-file .env -p 6000:6000 ai-hedge-fund-apicurl -X POST "http://localhost:6000/api/analysis" \
-H "Content-Type: application/json" \
-d '{
"tickers": "tsla",
"selectedAnalysts": ["ben_graham"],
"modelName": "gpt-4o"
}'| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
tickers |
string | ✅ | Stock symbols (comma-separated) | "AAPL,TSLA,NVDA" |
selectedAnalysts |
array | Analysts to use (empty=all) | ["ben_graham", "warren_buffett"] |
|
modelName |
string | ✅ | LLM model name | "gpt-4o", "claude-3-5-sonnet-20241022" |
startDate |
string | ❌ | Analysis start date (default: 3 months ago) | "2024-01-01" |
endDate |
string | ❌ | Analysis end date (default: today) | "2024-12-31" |
initialCash |
number | ❌ | Initial cash (default: 100000) | 100000 |
Available selectedAnalysts options: See the list in Chinese section above or leave empty to use all analysts.
(See JSON example in Chinese section)
