- Added pipeline_converging_triangle.py for streamlined execution of detection, reporting, and chart generation. - Introduced triangle_config.py for centralized parameter management across scripts. - Updated plot_converging_triangles.py to utilize parameters from the new config file. - Revised report_converging_triangles.py to reflect dynamic detection window based on configuration. - Enhanced existing scripts for improved error handling and output consistency. - Added new documentation files for usage instructions and parameter configurations.
167 lines
5.1 KiB
Python
167 lines
5.1 KiB
Python
"""
|
||
收敛三角形检测参数配置
|
||
|
||
所有相关脚本共享此配置,确保参数一致性:
|
||
- run_converging_triangle.py (批量检测)
|
||
- report_converging_triangles.py (报告生成)
|
||
- plot_converging_triangles.py (图表绘制)
|
||
"""
|
||
|
||
import os
|
||
import sys
|
||
|
||
# 让脚本能找到 src/ 下的模块
|
||
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "src"))
|
||
|
||
from converging_triangle import ConvergingTriangleParams
|
||
|
||
|
||
# ============================================================================
|
||
# 核心检测参数
|
||
# ============================================================================
|
||
|
||
# 严格模式:更严格的收敛和突破要求(当前激活)
|
||
DETECTION_PARAMS = ConvergingTriangleParams(
|
||
# 基础窗口
|
||
window=120, # 检测窗口大小(交易日)
|
||
pivot_k=15, # 枢轴点检测周期
|
||
|
||
# 边界拟合
|
||
boundary_n_segments=2, # 边界线分段数
|
||
boundary_source="full", # 边界拟合数据源: "full"(全部) 或 "pivot"(仅枢轴点)
|
||
|
||
# 斜率约束
|
||
upper_slope_max=0.10, # 上沿最大斜率(正值,向上倾斜)
|
||
lower_slope_min=-0.10, # 下沿最小斜率(负值,向下倾斜)
|
||
|
||
# 触碰检测
|
||
touch_tol=0.10, # 触碰容差(10%以内算触碰)
|
||
touch_loss_max=0.10, # 平均触碰误差上限
|
||
|
||
# 收敛度要求
|
||
shrink_ratio=0.6, # 🔧 更严格:末端≤60%起始宽度
|
||
|
||
# 突破检测
|
||
break_tol=0.005, # 🔧 更明显的突破(0.5%)
|
||
|
||
# 成交量确认
|
||
vol_window=20, # 成交量移动窗口
|
||
vol_k=1.5, # 🔧 更强的放量要求
|
||
|
||
# 假突破过滤
|
||
false_break_m=5, # 假突破回看天数
|
||
)
|
||
|
||
# 默认模式(备用)
|
||
DEFAULT_PARAMS = ConvergingTriangleParams(
|
||
window=120,
|
||
pivot_k=15,
|
||
boundary_n_segments=2,
|
||
boundary_source="full",
|
||
upper_slope_max=0.10,
|
||
lower_slope_min=-0.10,
|
||
touch_tol=0.10,
|
||
touch_loss_max=0.10,
|
||
shrink_ratio=0.8,
|
||
break_tol=0.001,
|
||
vol_window=20,
|
||
vol_k=1.3,
|
||
false_break_m=5,
|
||
)
|
||
|
||
|
||
# ============================================================================
|
||
# 数据范围配置
|
||
# ============================================================================
|
||
|
||
# 计算范围:None = 全部历史,具体数字 = 最近N天
|
||
RECENT_DAYS = 500
|
||
|
||
# 显示范围:图表中显示的交易日数
|
||
DISPLAY_WINDOW = 500
|
||
|
||
|
||
# ============================================================================
|
||
# 输出控制
|
||
# ============================================================================
|
||
|
||
# 是否只输出有效三角形
|
||
ONLY_VALID = True
|
||
|
||
# 是否显示详细日志
|
||
VERBOSE = True
|
||
|
||
# ============================================================================
|
||
# 推荐参数预设(备选方案)
|
||
# ============================================================================
|
||
|
||
# 宽松模式:捕获更多潜在形态
|
||
LOOSE_PARAMS = ConvergingTriangleParams(
|
||
window=120,
|
||
pivot_k=15,
|
||
boundary_n_segments=2,
|
||
boundary_source="full",
|
||
upper_slope_max=0.15, # 允许更陡峭的斜率
|
||
lower_slope_min=-0.15,
|
||
touch_tol=0.12,
|
||
touch_loss_max=0.12,
|
||
shrink_ratio=0.85, # 更宽松的收敛要求
|
||
break_tol=0.001,
|
||
vol_window=20,
|
||
vol_k=1.2,
|
||
false_break_m=5,
|
||
)
|
||
|
||
|
||
# ============================================================================
|
||
# 使用说明
|
||
# ============================================================================
|
||
|
||
def get_params(mode: str = "strict") -> ConvergingTriangleParams:
|
||
"""
|
||
获取检测参数
|
||
|
||
Args:
|
||
mode: 参数模式,可选值:
|
||
- "strict": 严格模式(当前默认,推荐)
|
||
- "default": 默认参数
|
||
- "loose": 宽松模式
|
||
|
||
Returns:
|
||
ConvergingTriangleParams 实例
|
||
"""
|
||
if mode == "default":
|
||
return DEFAULT_PARAMS
|
||
elif mode == "loose":
|
||
return LOOSE_PARAMS
|
||
else:
|
||
return DETECTION_PARAMS # strict
|
||
|
||
|
||
if __name__ == "__main__":
|
||
print("=" * 70)
|
||
print("收敛三角形检测参数配置")
|
||
print("=" * 70)
|
||
print("\n[当前激活: 严格模式]")
|
||
print(f" 检测窗口: {DETECTION_PARAMS.window} 个交易日")
|
||
print(f" 收敛比例: ≤ {DETECTION_PARAMS.shrink_ratio} (末端宽度/起始宽度)")
|
||
print(f" 突破阈值: {DETECTION_PARAMS.break_tol * 100:.2f}%")
|
||
print(f" 放量倍数: ≥ {DETECTION_PARAMS.vol_k}x")
|
||
|
||
print("\n[数据范围]")
|
||
print(f" 计算范围: 最近 {RECENT_DAYS} 个交易日")
|
||
print(f" 图表显示: {DISPLAY_WINDOW} 个交易日")
|
||
|
||
print("\n[可选模式]")
|
||
print(" - strict: 严格模式(当前使用,高质量)")
|
||
print(" - default: 默认参数(较宽松)")
|
||
print(" - loose: 宽松模式(更多候选)")
|
||
|
||
print("\n[关键差异]")
|
||
print(" 参数 | 严格模式 | 默认模式 | 宽松模式")
|
||
print(" ------------|---------|---------|----------")
|
||
print(" 收敛比例 | ≤0.6 | ≤0.8 | ≤0.85")
|
||
print(" 突破阈值 | 0.5% | 0.1% | 0.1%")
|
||
print(" 放量倍数 | ≥1.5x | ≥1.3x | ≥1.2x")
|
||
print("=" * 70)
|