update pay function
This commit is contained in:
710
mcp_server.py
710
mcp_server.py
@@ -15,6 +15,7 @@ import httpx
|
||||
import time
|
||||
from enum import Enum
|
||||
import mcp_database as db
|
||||
import mcp_quant as quant # 量化因子计算模块
|
||||
from openai import OpenAI
|
||||
import json
|
||||
import asyncio
|
||||
@@ -770,6 +771,566 @@ TOOLS: List[ToolDefinition] = [
|
||||
"required": ["code", "date"]
|
||||
}
|
||||
),
|
||||
# ==================== 量化因子工具 ====================
|
||||
ToolDefinition(
|
||||
name="get_macd_signal",
|
||||
description="获取MACD趋势判定信号,包括金叉/死叉、动能增减、顶底背离等状态。适用于判断股票短期趋势方向。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认60天",
|
||||
"default": 60
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="check_oscillator_status",
|
||||
description="检查KDJ/RSI超买超卖状态,判断股票是否处于超买区(风险积聚)或超卖区(可能反弹)。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认60天",
|
||||
"default": 60
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="analyze_bollinger_bands",
|
||||
description="分析布林带通道,判断股价是在中轨之上(强势)、触及上轨(压力)、触及下轨(支撑)或布林带收窄(变盘在即)。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认60天",
|
||||
"default": 60
|
||||
},
|
||||
"period": {
|
||||
"type": "integer",
|
||||
"description": "布林带周期,默认20",
|
||||
"default": 20
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_stop_loss_atr",
|
||||
description="使用ATR真实波幅计算止损位。告诉用户\"如果买入,止损点应该设在当前价格减去N倍ATR的位置\"。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认30天",
|
||||
"default": 30
|
||||
},
|
||||
"atr_multiplier": {
|
||||
"type": "number",
|
||||
"description": "ATR倍数,默认2倍",
|
||||
"default": 2.0
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="analyze_market_heat",
|
||||
description="分析换手率活跃度和量能,判断股票是冷门股、活跃股还是妖股,以及主力是在吸筹还是出货。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认30天",
|
||||
"default": 30
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="check_new_high_breakout",
|
||||
description="检查唐奇安通道突破(海龟交易法则),判断是否突破20日/60日新高或新低。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认60天",
|
||||
"default": 60
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="identify_candlestick_pattern",
|
||||
description="识别K线组合形态,如早晨之星(反转信号)、红三兵(上涨信号)、穿头破脚(吞没形态)等经典形态。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认10天",
|
||||
"default": 10
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="find_price_gaps",
|
||||
description="寻找跳空缺口,筛选出近期有未回补缺口的情况。缺口往往代表主力资金的强势突破意图或恐慌抛售。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认30天",
|
||||
"default": 30
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="check_volume_price_divergence",
|
||||
description="检测量价背离。股价创新高但成交量萎缩(量价背离),预警信号,提示上涨动力不足。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认20天",
|
||||
"default": 20
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_max_drawdown",
|
||||
description="计算最大回撤和夏普比率。用于评估\"买这只票最坏情况会亏多少\"以及风险调整后收益。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认250天(约一年)",
|
||||
"default": 250
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="check_valuation_rank",
|
||||
description="检查历史PE/PB百分位估值。计算当前PE处于过去N年的什么位置(例如:比过去90%的时间都便宜)。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"years": {
|
||||
"type": "integer",
|
||||
"description": "历史年数,默认3年",
|
||||
"default": 3
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_price_zscore",
|
||||
description="计算价格Z-Score(乖离率标准化),判断均值回归概率。当Z-Score过大时,统计回调概率。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"period": {
|
||||
"type": "integer",
|
||||
"description": "均线周期,默认60日",
|
||||
"default": 60
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_market_profile_vpoc",
|
||||
description="计算市场轮廓VPOC(成交量最大的价格档位),基于分钟级数据。VPOC是当日极强的支撑线或阻力线。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"date": {
|
||||
"type": "string",
|
||||
"description": "日期,格式:YYYY-MM-DD"
|
||||
}
|
||||
},
|
||||
"required": ["code", "date"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_realized_volatility",
|
||||
description="计算已实现波动率(RV),基于分钟级数据。比日线波动率更精准,用于判断趋势动能是否耗尽。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"date": {
|
||||
"type": "string",
|
||||
"description": "日期,格式:YYYY-MM-DD"
|
||||
}
|
||||
},
|
||||
"required": ["code", "date"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="analyze_buying_pressure",
|
||||
description="分析买卖压力失衡,基于分钟级数据。捕捉盘中主力资金的\"抢筹\"或\"砸盘\"意图。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"date": {
|
||||
"type": "string",
|
||||
"description": "日期,格式:YYYY-MM-DD"
|
||||
}
|
||||
},
|
||||
"required": ["code", "date"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="get_comprehensive_analysis",
|
||||
description="综合技术分析,一次性返回MACD、KDJ/RSI、布林带、量能、突破、K线形态等多个指标,并给出多空信号总结。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
|
||||
# ==================== 新增量化因子工具(12个) ====================
|
||||
|
||||
ToolDefinition(
|
||||
name="calc_rsi_divergence",
|
||||
description="RSI背离检测,独立分析RSI指标的顶背离和底背离信号,判断反转概率。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认60",
|
||||
"default": 60
|
||||
},
|
||||
"rsi_period": {
|
||||
"type": "integer",
|
||||
"description": "RSI周期,默认14",
|
||||
"default": 14
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_bollinger_squeeze",
|
||||
description="布林带挤压分析,检测布林带收窄程度,预判变盘时机。当带宽处于历史低位时发出变盘预警。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认60",
|
||||
"default": 60
|
||||
},
|
||||
"period": {
|
||||
"type": "integer",
|
||||
"description": "布林带周期,默认20",
|
||||
"default": 20
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="analyze_obv_trend",
|
||||
description="OBV能量潮独立分析,追踪资金流向,检测OBV与价格的背离,判断主力动向。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认60",
|
||||
"default": 60
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_amihud_illiquidity",
|
||||
description="计算Amihud非流动性因子,衡量股票流动性。值越大表示流动性越差,大单交易冲击成本越高。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认20",
|
||||
"default": 20
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_parkinson_volatility",
|
||||
description="计算帕金森波动率(基于分钟级高低价),比传统波动率更准确,适用于日内波动分析。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"date": {
|
||||
"type": "string",
|
||||
"description": "日期,格式YYYY-MM-DD"
|
||||
}
|
||||
},
|
||||
"required": ["code", "date"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_trend_slope",
|
||||
description="计算趋势线性回归斜率,量化趋势强度和方向。返回斜率、R²拟合度和趋势判断。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认20",
|
||||
"default": 20
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_hurst_exponent",
|
||||
description="计算Hurst指数,判断市场是趋势型(H>0.5)还是均值回归型(H<0.5),指导策略选择。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,建议100以上",
|
||||
"default": 100
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="test_cointegration",
|
||||
description="协整性测试,用于配对交易。检测两只股票是否存在长期均衡关系,计算对冲比率和价差。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code1": {
|
||||
"type": "string",
|
||||
"description": "股票代码1"
|
||||
},
|
||||
"code2": {
|
||||
"type": "string",
|
||||
"description": "股票代码2"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认250",
|
||||
"default": 250
|
||||
}
|
||||
},
|
||||
"required": ["code1", "code2"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_kelly_position",
|
||||
description="凯利公式计算最优仓位。根据胜率和盈亏比计算理论最优仓位,并提供保守建议。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"win_rate": {
|
||||
"type": "number",
|
||||
"description": "胜率(0-1之间,如0.6表示60%)"
|
||||
},
|
||||
"win_loss_ratio": {
|
||||
"type": "number",
|
||||
"description": "盈亏比(平均盈利/平均亏损)"
|
||||
},
|
||||
"max_position": {
|
||||
"type": "number",
|
||||
"description": "最大允许仓位,默认0.25",
|
||||
"default": 0.25
|
||||
}
|
||||
},
|
||||
"required": ["win_rate", "win_loss_ratio"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="search_similar_kline",
|
||||
description="相似K线检索,在历史中搜索与当前形态相似的K线组合,统计历史后续走势作为参考。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"lookback": {
|
||||
"type": "integer",
|
||||
"description": "匹配窗口大小,默认10天",
|
||||
"default": 10
|
||||
},
|
||||
"top_n": {
|
||||
"type": "integer",
|
||||
"description": "返回最相似的N个历史片段,默认5",
|
||||
"default": 5
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="decompose_trend_simple",
|
||||
description="趋势分解分析,将价格序列分解为趋势+周期+残差,识别主周期和趋势方向。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认120",
|
||||
"default": 120
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="calc_price_entropy",
|
||||
description="计算价格信息熵,衡量市场混乱程度。熵值越低表示趋势越明显,越高表示随机性越强。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码"
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "分析天数,默认60",
|
||||
"default": 60
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
]
|
||||
|
||||
# ==================== MCP协议端点 ====================
|
||||
@@ -1251,6 +1812,8 @@ TOOL_HANDLERS = {
|
||||
"get_stock_minute_data": handle_get_stock_minute_data,
|
||||
"get_stock_minute_aggregation": handle_get_stock_minute_aggregation,
|
||||
"get_stock_intraday_statistics": handle_get_stock_intraday_statistics,
|
||||
# 量化因子工具(从 mcp_quant 模块导入)
|
||||
**quant.QUANT_TOOLS,
|
||||
}
|
||||
|
||||
# ==================== Agent系统实现 ====================
|
||||
@@ -2202,10 +2765,18 @@ async def agent_chat(request: AgentChatRequest):
|
||||
except Exception as e:
|
||||
logger.error(f"保存用户消息失败: {e}")
|
||||
|
||||
# 获取工具列表
|
||||
tools = [tool.dict() for tool in TOOLS]
|
||||
# 获取工具列表(根据前端选择过滤)
|
||||
if request.tools and len(request.tools) > 0:
|
||||
# 用户指定了工具列表,按名称过滤
|
||||
selected_tool_names = set(request.tools)
|
||||
tools = [tool.dict() for tool in TOOLS if tool.name in selected_tool_names]
|
||||
logger.info(f"使用用户选择的 {len(tools)} 个工具: {request.tools[:10]}...")
|
||||
else:
|
||||
# 用户未指定,使用全部工具
|
||||
tools = [tool.dict() for tool in TOOLS]
|
||||
logger.info(f"使用全部 {len(tools)} 个工具")
|
||||
|
||||
# 添加特殊工具:summarize_news
|
||||
# 添加特殊工具:summarize_news(始终可用)
|
||||
tools.append({
|
||||
"name": "summarize_news",
|
||||
"description": "使用 DeepMoney 模型总结新闻数据,提取关键信息",
|
||||
@@ -2510,7 +3081,28 @@ def clean_deepseek_tool_markers(content: str) -> str:
|
||||
ROLE_TOOLS = {
|
||||
"buffett": ["search_china_news", "search_research_reports", "get_stock_basic_info", "get_stock_financial_index"],
|
||||
"big_short": ["search_china_news", "get_stock_financial_index", "get_stock_balance_sheet", "get_stock_cashflow"],
|
||||
"simons": ["get_stock_trade_data", "search_limit_up_stocks", "get_concept_statistics"],
|
||||
"simons": [
|
||||
# 基础数据
|
||||
"get_stock_trade_data", "search_limit_up_stocks", "get_concept_statistics",
|
||||
# 经典技术指标
|
||||
"get_macd_signal", "check_oscillator_status", "analyze_bollinger_bands", "calc_stop_loss_atr",
|
||||
# 资金与情绪
|
||||
"analyze_market_heat", "check_volume_price_divergence", "analyze_obv_trend",
|
||||
# 形态与突破
|
||||
"check_new_high_breakout", "identify_candlestick_pattern", "find_price_gaps",
|
||||
# 风险与估值
|
||||
"calc_max_drawdown", "check_valuation_rank", "calc_price_zscore",
|
||||
# 分钟级高阶算子
|
||||
"calc_market_profile_vpoc", "calc_realized_volatility", "analyze_buying_pressure", "calc_parkinson_volatility",
|
||||
# 高级趋势分析
|
||||
"calc_bollinger_squeeze", "calc_trend_slope", "calc_hurst_exponent", "decompose_trend_simple",
|
||||
# 流动性与统计
|
||||
"calc_amihud_illiquidity", "calc_price_entropy", "calc_rsi_divergence",
|
||||
# 配对与策略
|
||||
"test_cointegration", "calc_kelly_position", "search_similar_kline",
|
||||
# 综合分析
|
||||
"get_comprehensive_analysis",
|
||||
],
|
||||
"leek": [], # 韭菜不用工具
|
||||
"fund_manager": ["search_china_news", "search_research_reports", "get_stock_basic_info"],
|
||||
}
|
||||
@@ -2624,61 +3216,93 @@ MEETING_ROLES = {
|
||||
},
|
||||
"simons": {
|
||||
"id": "simons",
|
||||
"name": "量化分析员",
|
||||
"name": "量化研究员",
|
||||
"nickname": "西蒙斯",
|
||||
"role_type": "quant",
|
||||
"avatar": "/images/agent/simons.png",
|
||||
"model": "kimi-k2-thinking",
|
||||
"color": "#3B82F6",
|
||||
"description": "中性立场,使用量化工具分析技术指标",
|
||||
"description": "中性立场,使用专业量化因子分析技术指标和市场特征",
|
||||
"tools": ROLE_TOOLS["simons"],
|
||||
"system_prompt": """你是"量化分析员"(昵称:西蒙斯),一位专业的量化交易研究员。你在投研会议中担任「技术分析师」角色,保持中性客观。
|
||||
"system_prompt": """你是"量化研究员"(昵称:西蒙斯),一位专业的量化交易研究员,擅长使用各类量化因子分析市场。你在投研会议中担任「技术分析师」角色,保持中性客观。
|
||||
|
||||
## 你的分析理念
|
||||
- **数据驱动**:让数据说话,不带主观情绪
|
||||
- **因子驱动**:使用经过验证的量化因子,而非主观判断
|
||||
- **概率思维**:没有确定性,只有概率和赔率
|
||||
- **趋势跟踪**:顺势而为,不与趋势作对
|
||||
- **风险量化**:用数字衡量风险,而非感觉
|
||||
- **多维验证**:从趋势、动量、波动、资金多个维度交叉验证
|
||||
- **风险量化**:用数字衡量风险,止损止盈有据可依
|
||||
|
||||
## 分析框架(请按此思维链分析)
|
||||
## 你可用的量化因子工具(28个)
|
||||
|
||||
### 第一步:收集数据
|
||||
必须先调用工具获取量化数据:
|
||||
- `get_stock_trade_data`: 获取价格、成交量、涨跌幅等交易数据
|
||||
- `search_limit_up_stocks`: 了解涨停板情况,判断市场情绪
|
||||
- `get_concept_statistics`: 获取概念板块统计,判断资金流向
|
||||
### 快速综合分析(推荐首选)
|
||||
- `get_comprehensive_analysis`: 一次性获取MACD、RSI、KDJ、布林带、量能、K线形态等多指标汇总
|
||||
|
||||
### 第二步:技术分析维度
|
||||
基于获取的数据,进行量化分析:
|
||||
1. **趋势判断**:
|
||||
- 当前价格在均线系统中的位置(MA5/MA10/MA20/MA60)
|
||||
- 是多头排列还是空头排列?
|
||||
- 趋势强度如何?
|
||||
2. **量价分析**:
|
||||
- 成交量变化趋势?放量还是缩量?
|
||||
- 量价配合是否健康?(上涨放量、下跌缩量为佳)
|
||||
- 换手率处于什么水平?
|
||||
3. **动能指标**:
|
||||
- 涨跌幅在同行/板块中的排名
|
||||
- 连续上涨/下跌天数
|
||||
- 离前高/前低的距离
|
||||
4. **板块联动**:
|
||||
- 所属概念板块表现如何?
|
||||
- 是板块龙头还是跟风?
|
||||
- 板块资金流入还是流出?
|
||||
### 趋势与动量因子
|
||||
- `get_macd_signal`: MACD趋势判定(金叉/死叉/背离)
|
||||
- `calc_trend_slope`: 趋势线性回归斜率(R²拟合度)
|
||||
- `calc_hurst_exponent`: Hurst指数(判断趋势/震荡市场)
|
||||
- `check_new_high_breakout`: 唐奇安通道突破(新高/新低信号)
|
||||
|
||||
### 超买超卖因子
|
||||
- `check_oscillator_status`: KDJ/RSI超买超卖状态
|
||||
- `calc_rsi_divergence`: RSI背离检测(顶底背离)
|
||||
- `calc_price_zscore`: Z-Score均值回归(乖离率标准化)
|
||||
|
||||
### 波动率因子
|
||||
- `analyze_bollinger_bands`: 布林带通道分析
|
||||
- `calc_bollinger_squeeze`: 布林带挤压(变盘预警)
|
||||
- `calc_stop_loss_atr`: ATR动态止损位
|
||||
- `calc_realized_volatility`: 分钟级已实现波动率
|
||||
- `calc_parkinson_volatility`: 帕金森波动率(更精确)
|
||||
|
||||
### 资金流向与量价因子
|
||||
- `analyze_market_heat`: 换手率活跃度+OBV趋势
|
||||
- `analyze_obv_trend`: OBV能量潮独立分析
|
||||
- `check_volume_price_divergence`: 量价背离检测
|
||||
- `analyze_buying_pressure`: 买卖压力失衡(主力意图)
|
||||
- `calc_market_profile_vpoc`: VPOC筹码峰(成交密集区)
|
||||
|
||||
### 形态识别因子
|
||||
- `identify_candlestick_pattern`: K线组合形态(10+种)
|
||||
- `find_price_gaps`: 跳空缺口分析
|
||||
- `search_similar_kline`: 相似K线检索(历史形态预测)
|
||||
|
||||
### 风险与估值因子
|
||||
- `calc_max_drawdown`: 最大回撤+夏普比率
|
||||
- `check_valuation_rank`: PE历史百分位+PEG
|
||||
- `calc_amihud_illiquidity`: Amihud流动性因子
|
||||
|
||||
### 高级分析因子
|
||||
- `decompose_trend_simple`: 趋势分解(趋势+周期+残差)
|
||||
- `calc_price_entropy`: 价格熵值(市场混乱度)
|
||||
- `test_cointegration`: 协整性测试(配对交易)
|
||||
- `calc_kelly_position`: 凯利公式最优仓位
|
||||
|
||||
## 分析框架(请按此流程)
|
||||
|
||||
### 第一步:快速扫描
|
||||
首先调用 `get_comprehensive_analysis` 获取综合技术面快照,了解整体状况。
|
||||
|
||||
### 第二步:深度分析(根据情况选择)
|
||||
根据综合分析结果,选择相关因子深入分析:
|
||||
- 如果趋势不明:调用 `calc_hurst_exponent` 判断市场类型,`calc_trend_slope` 量化趋势强度
|
||||
- 如果疑似顶底:调用 `calc_rsi_divergence` 检测背离,`calc_bollinger_squeeze` 看是否变盘
|
||||
- 如果量能异常:调用 `analyze_obv_trend` 看资金流向,`analyze_buying_pressure` 看主力意图
|
||||
- 如果波动加大:调用 `calc_realized_volatility` 或 `calc_parkinson_volatility` 精确测量
|
||||
- 如果要设止损:调用 `calc_stop_loss_atr` 获取ATR止损位
|
||||
|
||||
### 第三步:形成结论
|
||||
给出客观的技术分析结论,必须包含:
|
||||
- **趋势判断**(上涨/下跌/震荡)
|
||||
- **关键数据**(引用具体的价格、成交量、涨跌幅数据)
|
||||
- **技术位**(支撑位、压力位)
|
||||
- **量化建议**(从概率角度给出建议)
|
||||
给出量化分析结论,必须包含:
|
||||
- **核心因子信号**(列出2-3个关键因子的具体数值和判断)
|
||||
- **趋势判断**(上涨/下跌/震荡,并给出概率估计)
|
||||
- **关键价位**(支撑位、压力位、止损位)
|
||||
- **量化建议**(基于因子信号的交易建议)
|
||||
|
||||
## 输出要求
|
||||
- 必须基于工具返回的数据分析,用数字说话
|
||||
- 保持中性客观,不偏向多头或空头
|
||||
- 如果前面有多空分歧,可以从技术面给出参考
|
||||
- 发言控制在 200 字以内,精炼专业"""
|
||||
- **必须调用工具**:至少调用1个综合分析+1-2个专项因子
|
||||
- **数据说话**:每个结论都要有具体数值支撑
|
||||
- **保持中性**:不偏向多头或空头,让因子说话
|
||||
- **简洁专业**:发言控制在 300 字以内,用专业术语但要解释关键数值含义"""
|
||||
},
|
||||
"leek": {
|
||||
"id": "leek",
|
||||
|
||||
Reference in New Issue
Block a user