technical-patterns-lab/docs/2026-01-16_pkl_batch_detection.md
褚宏光 543572667b Add initial implementation of converging triangle detection algorithm and related documentation
- 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.
2026-01-21 18:02:58 +08:00

152 lines
3.8 KiB
Markdown
Raw Permalink 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-16
**任务**: 从 pkl 文件批量检测对称三角形
---
## 1. 数据源分析
### pkl 文件结构
| 文件 | 说明 |
|------|------|
| `open.pkl.pkl` | 开盘价矩阵 |
| `high.pkl.pkl` | 最高价矩阵 |
| `low.pkl.pkl` | 最低价矩阵 |
| `close.pkl.pkl` | 收盘价矩阵 |
| `volume.pkl.pkl` | 成交量矩阵 |
### pkl 内部数据结构
```python
{
'mtx_save': ndarray (108, 5113), # 主数据矩阵: 108只股票 × 5113个交易日
'tot_c': ndarray (108,), # 列索引 [0,1,2,...,107]
'tot_r': ndarray (5113,), # 有效行索引(日期序号,非连续)
'shape_c': 108, # 原始列数
'shape_r': 7698, # 原始总行数(含空行)
}
```
### 加载方式
两种加载方式对比:
| 方式 | 返回值 | 适用场景 |
|------|--------|----------|
| 原生 `pickle.load` | `dict` | 需要完整元数据 |
| `g.load_pkl` | `ndarray` | dataServer 环境内,直接使用矩阵 |
**本次采用**: 原生 `pickle.load` + 空壳模块绕过 `model` 依赖
```python
class FakeModule:
ndarray = np.ndarray
sys.modules['model'] = FakeModule()
sys.modules['model.index_info'] = FakeModule()
with open(pkl_path, 'rb') as f:
data = pickle.load(f)
```
---
## 2. 检测参数
```python
WINDOW = 400 # 分析窗口大小
PIVOT_K = 20 # 枢轴点检测窗口
BOUNDARY_N_SEGMENTS = 2 # 边界线分段数
BOUNDARY_SOURCE = "full" # 使用全量 high/low 拟合
UPPER_SLOPE_MAX = 0.10 # 上沿斜率最大值
LOWER_SLOPE_MIN = -0.10 # 下沿斜率最小值
TOUCH_TOL = 0.10 # 触碰容差
TOUCH_LOSS_MAX = 0.10 # 损失函数阈值
SHRINK_RATIO = 0.8 # 收敛比阈值
```
---
## 3. 运行结果
**扫描**: 108 只股票
**识别成功**: 10 只 (9.26%)
### 识别结果明细
| 股票 ID | 上沿斜率 | 下沿斜率 | 收敛比 | 触碰(上/下) | 突破方向 |
|---------|----------|----------|--------|-------------|----------|
| stock_017 | +0.0025 | +0.0071 | 0.25 | 5/3 | down |
| stock_019 | +0.0021 | +0.0056 | 0.63 | 5/4 | none |
| stock_025 | +0.0009 | +0.0020 | 0.75 | 5/5 | none |
| stock_031 | -0.0097 | -0.0042 | 0.64 | 3/4 | none |
| stock_057 | -0.0002 | +0.0036 | 0.46 | 5/4 | none |
| stock_063 | +0.0105 | +0.0329 | 0.19 | 7/6 | none |
| stock_066 | +0.0089 | +0.0115 | 0.62 | 5/4 | none |
| stock_079 | +0.0056 | +0.0081 | 0.55 | 4/5 | down |
| stock_081 | -0.0029 | +0.0029 | 0.15 | 4/3 | down |
| stock_095 | -0.0028 | +0.0025 | 0.38 | 5/3 | up |
### 突破统计
- **向上突破**: 1 只 (stock_095)
- **向下突破**: 3 只 (stock_017, stock_079, stock_081)
- **未突破**: 6 只
---
## 4. 输出文件
```
outputs/sym_triangles/
├── stock_017.png
├── stock_019.png
├── stock_025.png
├── stock_031.png
├── stock_057.png
├── stock_063.png
├── stock_066.png
├── stock_079.png
├── stock_081.png
├── stock_095.png
└── summary.csv
```
---
## 5. 脚本使用方法
```powershell
# 进入项目目录
cd D:\project\technical-patterns-lab
# 激活虚拟环境
.\.venv\Scripts\Activate.ps1
# 运行批量检测
python scripts/run_sym_triangle_pkl.py
```
---
## 6. 相关文件
| 文件 | 说明 |
|------|------|
| `scripts/run_sym_triangle_pkl.py` | 批量检测脚本 (pkl 数据源) |
| `scripts/run_sym_triangle_json.py` | 单股检测脚本 (JSON 数据源) |
| `src/sym_triangle.py` | 核心算法模块 |
| `data/*.pkl.pkl` | OHLCV 数据文件 |
| `data/map/stock_name.json` | 股票代码映射表 |
---
## 7. 待优化项
- [ ] 关联 `stock_name.json` 显示真实股票代码/名称
- [ ] 图表标题显示真实日期(当前显示索引)
- [ ] 支持自定义股票筛选范围
- [ ] 添加更多形态参数到汇总表