tushare
This commit is contained in:
+25
-31
@@ -1,5 +1,6 @@
|
||||
from deepseek_client import DeepSeekClient
|
||||
from typing import Dict, Any
|
||||
import concurrent.futures
|
||||
import time
|
||||
import config
|
||||
|
||||
@@ -13,7 +14,6 @@ class StockAnalysisAgents:
|
||||
def technical_analyst_agent(self, stock_info: Dict, stock_data: Any, indicators: Dict) -> Dict[str, Any]:
|
||||
"""技术面分析智能体"""
|
||||
print("🔍 技术分析师正在分析中...")
|
||||
time.sleep(1) # 模拟分析时间
|
||||
|
||||
analysis = self.deepseek_client.technical_analysis(stock_info, stock_data, indicators)
|
||||
|
||||
@@ -38,8 +38,6 @@ class StockAnalysisAgents:
|
||||
else:
|
||||
print(" ⚠ 未获取到季报数据,将基于基本财务数据分析")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
analysis = self.deepseek_client.fundamental_analysis(stock_info, financial_data, quarterly_data)
|
||||
|
||||
return {
|
||||
@@ -61,8 +59,6 @@ class StockAnalysisAgents:
|
||||
else:
|
||||
print(" ⚠ 未获取到资金流向数据,将基于技术指标分析")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
analysis = self.deepseek_client.fund_flow_analysis(stock_info, indicators, fund_flow_data)
|
||||
|
||||
return {
|
||||
@@ -84,8 +80,6 @@ class StockAnalysisAgents:
|
||||
else:
|
||||
print(" ⚠ 未获取到风险数据,将基于基本信息分析")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
# 构建风险数据文本
|
||||
risk_data_text = ""
|
||||
if risk_data and risk_data.get('data_success'):
|
||||
@@ -227,8 +221,6 @@ class StockAnalysisAgents:
|
||||
else:
|
||||
print(" ⚠ 未获取到详细情绪数据,将基于基本信息分析")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
# 构建带有市场情绪数据的prompt
|
||||
sentiment_data_text = ""
|
||||
if sentiment_data and sentiment_data.get('data_success'):
|
||||
@@ -317,8 +309,6 @@ class StockAnalysisAgents:
|
||||
else:
|
||||
print(" ⚠ 未获取到新闻数据,将基于基本信息分析")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
# 构建带有新闻数据的prompt
|
||||
news_text = ""
|
||||
if news_data and news_data.get('data_success'):
|
||||
@@ -436,32 +426,38 @@ class StockAnalysisAgents:
|
||||
print(f"📋 参与分析的分析师: {', '.join(active_analysts)}")
|
||||
print("=" * 50)
|
||||
|
||||
# 并行运行各个分析师
|
||||
# 并行运行各个分析师(全部同时启动,等待最慢的一个完成)
|
||||
agents_results = {}
|
||||
|
||||
# 技术面分析
|
||||
agent_jobs = []
|
||||
if enabled_analysts.get('technical', True):
|
||||
agents_results["technical"] = self.technical_analyst_agent(stock_info, stock_data, indicators)
|
||||
|
||||
# 基本面分析
|
||||
agent_jobs.append(("technical", lambda: self.technical_analyst_agent(stock_info, stock_data, indicators)))
|
||||
if enabled_analysts.get('fundamental', True):
|
||||
agents_results["fundamental"] = self.fundamental_analyst_agent(stock_info, financial_data, quarterly_data)
|
||||
|
||||
# 资金面分析(传入资金流向数据)
|
||||
agent_jobs.append(("fundamental", lambda: self.fundamental_analyst_agent(stock_info, financial_data, quarterly_data)))
|
||||
if enabled_analysts.get('fund_flow', True):
|
||||
agents_results["fund_flow"] = self.fund_flow_analyst_agent(stock_info, indicators, fund_flow_data)
|
||||
|
||||
# 风险管理分析(传入风险数据)
|
||||
agent_jobs.append(("fund_flow", lambda: self.fund_flow_analyst_agent(stock_info, indicators, fund_flow_data)))
|
||||
if enabled_analysts.get('risk', True):
|
||||
agents_results["risk_management"] = self.risk_management_agent(stock_info, indicators, risk_data)
|
||||
|
||||
# 市场情绪分析(传入市场情绪数据)
|
||||
agent_jobs.append(("risk_management", lambda: self.risk_management_agent(stock_info, indicators, risk_data)))
|
||||
if enabled_analysts.get('sentiment', False):
|
||||
agents_results["market_sentiment"] = self.market_sentiment_agent(stock_info, sentiment_data)
|
||||
|
||||
# 新闻分析(传入新闻数据)
|
||||
agent_jobs.append(("market_sentiment", lambda: self.market_sentiment_agent(stock_info, sentiment_data)))
|
||||
if enabled_analysts.get('news', False):
|
||||
agents_results["news"] = self.news_analyst_agent(stock_info, news_data)
|
||||
agent_jobs.append(("news", lambda: self.news_analyst_agent(stock_info, news_data)))
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=max(min(len(agent_jobs), 6), 1)) as executor:
|
||||
future_to_key = {executor.submit(job): key for key, job in agent_jobs}
|
||||
for future in concurrent.futures.as_completed(future_to_key):
|
||||
key = future_to_key[future]
|
||||
try:
|
||||
agents_results[key] = future.result()
|
||||
except Exception as e:
|
||||
print(f"❌ {key} 分析师并行分析失败: {e}")
|
||||
agents_results[key] = {
|
||||
"agent_name": key,
|
||||
"agent_role": "",
|
||||
"analysis": f"分析失败: {e}",
|
||||
"focus_areas": [],
|
||||
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
}
|
||||
|
||||
print("✅ 所有已选择的分析师完成分析")
|
||||
print("=" * 50)
|
||||
@@ -471,7 +467,6 @@ class StockAnalysisAgents:
|
||||
def conduct_team_discussion(self, agents_results: Dict[str, Any], stock_info: Dict) -> str:
|
||||
"""进行团队讨论"""
|
||||
print("🤝 分析团队正在进行综合讨论...")
|
||||
time.sleep(2)
|
||||
|
||||
# 收集参与分析的分析师名单和报告
|
||||
participants = []
|
||||
@@ -538,7 +533,6 @@ class StockAnalysisAgents:
|
||||
def make_final_decision(self, discussion_result: str, stock_info: Dict, indicators: Dict) -> Dict[str, Any]:
|
||||
"""制定最终投资决策"""
|
||||
print("📋 正在制定最终投资决策...")
|
||||
time.sleep(1)
|
||||
|
||||
decision = self.deepseek_client.final_decision(discussion_result, stock_info, indicators)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user