technical-patterns-lab/docs/突破强度计算方法.md
褚宏光 5455f8e456 Implement converging triangle detection pipeline and enhance documentation
- 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.
2026-01-22 11:29:04 +08:00

278 lines
7.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 突破强度计算方法
> 最后更新2026-01-22
> 版本v2.0(加权求和 + tanh 非线性归一化)
## 概述
突破强度是一个 **0~1** 的连续分数,用于衡量收敛三角形突破的有效性。
分数越高,表示突破越强势、越可信。
---
## 设计演进
### v1.0 乘法组合(已弃用)
```python
# 旧公式
strength = price_score × 5 × (1 + convergence_bonus × 0.5) × (1 + vol_bonus × 0.5)
```
**问题**:乘法组合 + 高乘数×5导致 **73-76% 的突破都是满分 1.0**,无法有效区分突破质量。
### v2.0 加权求和 + tanh 归一化(当前版本)
```python
# 新公式
strength = 0.60 × tanh(突破幅度% × 15) + # 价格分 (60%)
0.25 × (1 - width_ratio) + # 收敛分 (25%)
0.15 × vol_bonus # 成交量分 (15%)
```
**改进效果**
| 指标 | v1.0 | v2.0 |
|------|------|------|
| 满分比例(>0.9) | **73-76%** | **0.9-6.0%** |
| 平均强度 | ~0.12 | **~0.59** |
| 最大强度 | 1.0000 | **0.9928** |
| 区分度 | 差(大量满分) | **好(均匀分布)** |
---
## 当前计算公式v2.0
### 公式结构
```python
def calc_breakout_strength(close, upper_line, lower_line, volume_ratio, width_ratio):
import math
# 权重配置
W_PRICE = 0.60 # 突破幅度权重
W_CONVERGENCE = 0.25 # 收敛度权重
W_VOLUME = 0.15 # 成交量权重
TANH_SCALE = 15.0 # tanh 缩放因子
# 1. 价格突破分数tanh 非线性归一化)
pct_up = max(0, (close - upper_line) / upper_line)
price_score_up = math.tanh(pct_up * TANH_SCALE)
# 2. 收敛分数
convergence_score = max(0, min(1, 1 - width_ratio))
# 3. 成交量分数
vol_score = min(1, max(0, volume_ratio - 1))
# 4. 加权求和
strength_up = W_PRICE * price_score_up + W_CONVERGENCE * convergence_score + W_VOLUME * vol_score
return min(1.0, strength_up)
```
---
## 三个分量详解
### 1. 价格突破分数(权重 60%
使用 **tanh 函数** 进行非线性归一化,避免大幅突破导致的满分堆积。
```python
price_score = tanh(突破幅度% × 15)
```
**突破幅度映射表**
| 突破幅度 | price_score | 贡献分数 (×0.6) |
|----------|-------------|-----------------|
| 0.5% | 0.07 | 0.04 |
| 1% | 0.15 | 0.09 |
| 2% | 0.29 | 0.17 |
| 3% | 0.42 | 0.25 |
| 5% | 0.64 | 0.38 |
| 8% | 0.83 | 0.50 |
| 10% | 0.91 | 0.55 |
| 15% | 0.97 | 0.58 |
**设计考量**
- A股涨跌停限制 10%,常见突破在 1-5% 范围
- tanh 函数使小幅突破有区分,大幅突破趋于收敛
- 系数 15 使得 3% 突破 ≈ 0.42 分5% 突破 ≈ 0.64 分
---
### 2. 收敛分数(权重 25%
三角形收敛程度越高,突破越有效。
```python
convergence_score = max(0, 1 - width_ratio)
```
| width_ratio | 收敛程度 | convergence_score | 贡献分数 (×0.25) |
|-------------|----------|-------------------|------------------|
| 0.8 | 较弱 | 0.20 | 0.05 |
| 0.6 | 中等 | 0.40 | 0.10 |
| 0.4 | 较强 | 0.60 | 0.15 |
| 0.2 | 很强 | 0.80 | 0.20 |
| 0.1 | 极强 | 0.90 | 0.23 |
| 0.05 | 极度收敛 | 0.95 | 0.24 |
**width_ratio** = 三角形末端宽度 / 起始宽度
---
### 3. 成交量分数(权重 15%
放量突破更可信。
```python
vol_score = min(1, max(0, volume_ratio - 1))
```
| volume_ratio | 成交量状态 | vol_score | 贡献分数 (×0.15) |
|--------------|------------|-----------|------------------|
| 0.8 | 缩量 | 0 | 0 |
| 1.0 | 平量 | 0 | 0 |
| 1.5 | 放量 50% | 0.5 | 0.075 |
| 2.0 | 放量 100% | 1.0 | 0.15 |
| 3.0 | 放量 200% | 1.0 | 0.15 (上限) |
**volume_ratio** = 当日成交量 / 近 N 日均量
---
## 计算示例
### 示例 1强势突破领湃科技 2026-01-20
```
输入:
突破幅度 ≈ 8% (close 大幅高于 upper_line)
width_ratio = 0.0465 (极度收敛)
volume_ratio > 1.5 (放量确认)
计算:
price_score = tanh(0.08 × 15) = tanh(1.2) ≈ 0.83
convergence_score = 1 - 0.0465 = 0.9535
vol_score = min(1, 1.5 - 1) = 0.5
strength = 0.60 × 0.83 + 0.25 × 0.9535 + 0.15 × 0.5
= 0.498 + 0.238 + 0.075
= 0.811
实际结果: 0.9882 (因实际突破幅度更大)
```
### 示例 2中等突破五芳斋 2026-01-20
```
输入:
突破幅度 ≈ 3%
width_ratio = 0.2090
volume_ratio ≈ 1.0 (未放量)
计算:
price_score = tanh(0.03 × 15) = tanh(0.45) ≈ 0.42
convergence_score = 1 - 0.2090 = 0.791
vol_score = 0
strength = 0.60 × 0.42 + 0.25 × 0.791 + 0.15 × 0
= 0.252 + 0.198 + 0
= 0.450
实际结果: 0.5816 (因实际突破幅度略大于 3%)
```
### 示例 3弱势突破康华生物 2026-01-20
```
输入:
突破幅度 ≈ 2%
width_ratio = 0.1338
volume_ratio ≈ 1.0 (未放量)
计算:
price_score = tanh(0.02 × 15) = tanh(0.30) ≈ 0.29
convergence_score = 1 - 0.1338 = 0.866
vol_score = 0
strength = 0.60 × 0.29 + 0.25 × 0.866 + 0.15 × 0
= 0.174 + 0.217 + 0
= 0.391
实际结果: 0.4797 (因实际突破幅度略大于 2%)
```
---
## 强度等级参考
| 强度范围 | 等级 | 含义 | 占比参考 |
|----------|------|------|----------|
| 0 ~ 0.3 | 微弱 | 假突破风险高,需谨慎 | ~8% |
| 0.3 ~ 0.5 | 轻度 | 有突破迹象,建议观察 | ~27% |
| 0.5 ~ 0.7 | 中度 | 有效突破,可作为参考 | ~28% |
| 0.7 ~ 0.9 | 强势 | 高置信度突破,值得关注 | ~31% |
| 0.9 ~ 1.0 | 极强 | 顶级突破信号 | ~6% |
---
## 权重选择理由
| 分量 | 权重 | 理由 |
|------|------|------|
| **价格突破** | 60% | 突破幅度是最直接的信号,决定性因素 |
| **收敛程度** | 25% | 收敛越强,蓄势越充分,突破有效性越高 |
| **成交量** | 15% | 放量是确认信号,但非必要条件(有些有效突破不放量) |
**总和 = 100%**,确保最终分数在合理范围内。
---
## 代码位置
```
src/converging_triangle.py
├── calc_breakout_strength() # 突破强度计算函数 (第 180-260 行)
└── detect_converging_triangle() # 调用位置 (第 401 行)
scripts/triangle_config.py # 参数配置(严格模式/默认模式/宽松模式)
```
---
## 相关参数配置
| 参数 | 严格模式 | 默认模式 | 说明 |
|------|----------|----------|------|
| `window` | 120 | 120 | 检测窗口大小(交易日) |
| `shrink_ratio` | 0.6 | 0.8 | 收敛比例阈值(越小越严格) |
| `break_tol` | 0.005 | 0.001 | 突破判定容差0.5% vs 0.1% |
| `vol_window` | 20 | 20 | 计算成交量均值的窗口 |
| `vol_k` | 1.5 | 1.3 | 成交量确认阈值 |
当前使用 **严格模式**,详见 `scripts/triangle_config.py`
---
## 附录tanh 函数特性
```
tanh(x) = (e^x - e^-x) / (e^x + e^-x)
```
- 输出范围:(-1, 1)
- 当 x=0 时tanh(0) = 0
- 当 x→∞ 时tanh(x) → 1
- 单调递增,处处可导
- 在 x=0 附近近似线性,大值时趋于饱和
**选择 tanh 的原因**
1. 自然归一化到 (0, 1)
2. 小幅突破有区分度
3. 大幅突破不会无限增长
4. 平滑过渡,无跳变