- Created README.md and USAGE.md for project overview and usage instructions. - Added core algorithm in src/converging_triangle.py for batch processing of stock data. - Introduced data files (open.pkl, high.pkl, low.pkl, close.pkl, volume.pkl) for OHLCV data. - Developed output documentation for results and breakout strength calculations. - Implemented scripts for running the detection and generating reports. - Added SVG visualizations and markdown documentation for algorithm details and usage examples.
76 lines
2.1 KiB
Markdown
76 lines
2.1 KiB
Markdown
# 对称三角形识别 - 代码讲解一页PPT
|
||
|
||
## 1. 算法总体流程(5步)
|
||
输入数据 → 枢轴点检测 → 边界线拟合 → 几何约束验证 → 突破判定 → 输出结果
|
||
|
||
---
|
||
|
||
## 2. 核心模块与函数
|
||
|
||
**(1) 枢轴点检测**
|
||
函数:`pivots_fractal(high, low, k)`
|
||
作用:从高低价序列中提取明显峰谷
|
||
关键参数:`pivot_k`(越大越严格)
|
||
|
||
**(2) 边界线拟合**
|
||
函数:`fit_boundary_line(x, y, mode, n_segments)`
|
||
作用:按时间分段取极值点,拟合贴边趋势线
|
||
关键参数:`boundary_n_segments`(越小越贴边)
|
||
|
||
**(3) 形态验证**
|
||
函数:`detect_sym_triangle(...)`
|
||
包含:斜率约束、收敛判断、触碰次数、突破确认
|
||
|
||
---
|
||
|
||
## 3. 几何约束(对称三角形判定)
|
||
|
||
- 上沿下降:`a_u <= upper_slope_max`
|
||
- 下沿上升:`a_l > 0`
|
||
- 收敛比例:`width_end / width_start <= shrink_ratio`
|
||
- 触碰次数:上下沿均 ≥ 2 次
|
||
|
||
---
|
||
|
||
## 4. 突破与确认逻辑
|
||
|
||
- 向上突破:`close[end] > upper_end * (1 + break_tol)`
|
||
- 向下突破:`close[end] < lower_end * (1 - break_tol)`
|
||
- 成交量确认(可选):`volume[end] > MA(volume) * vol_k`
|
||
- 假突破过滤:突破后 `m` 根内回到线内
|
||
|
||
---
|
||
|
||
## 5. 关键参数(调参入口)
|
||
|
||
| 参数 | 含义 | 建议范围 |
|
||
|------|------|---------|
|
||
| `WINDOW` | 最近窗口长度 | 200~500 |
|
||
| `PIVOT_K` | 枢轴检测窗口 | 5~30 |
|
||
| `BOUNDARY_N_SEGMENTS` | 分段数 | 2~5 |
|
||
| `UPPER_SLOPE_MAX` | 上沿斜率上限 | -0.01~0.10 |
|
||
| `SHRINK_RATIO` | 收敛比例 | 0.3~0.9 |
|
||
| `TOUCH_TOL` | 触碰容差 | 0.03~0.15 |
|
||
|
||
---
|
||
|
||
## 6. 结果输出结构
|
||
|
||
`SymTriangleResult` 包含:
|
||
- 识别区间:`start, end`
|
||
- 趋势线:`upper_coef, lower_coef`
|
||
- 收敛程度:`width_ratio`
|
||
- 触碰次数:`touches_upper, touches_lower`
|
||
- 突破信息:`breakout, volume_confirmed, false_breakout`
|
||
|
||
---
|
||
|
||
## 7. 文件组织
|
||
|
||
```
|
||
code/
|
||
├── sym_triangle.py # 核心算法(检测+拟合+判定)
|
||
├── run_sym_triangle_json.py # 测试脚本(参数配置+可视化)
|
||
└── data.json # 输入数据(labels/values)
|
||
```
|