technical-patterns-lab/discuss/20260128-讨论.md
褚宏光 3538b214ba Enhance stock analysis features with K线图 and daily best reporting
- Upgraded charting functionality from line graphs to K线图 for improved technical analysis.
- Introduced a new daily best stocks report, outputting the top-performing stocks over the last 500 days.
- Implemented automatic logging of execution details for better traceability.
- Updated the .gitignore to include new output files related to the K线图 and logs.

Files modified:
- scripts/plot_converging_triangles.py: Enhanced to support K线图 rendering.
- scripts/run_converging_triangle.py: Added logging and daily best reporting features.
- README.md: Updated to reflect new features and usage instructions.
- New files: docs/K线图说明.md for detailed K线图 usage and features.
2026-01-29 09:09:29 +08:00

152 lines
4.1 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-28 讨论
## 1. K线图升级 📊
### 修改内容
- ✅ 图表从折线图升级为**K线图**
- ✅ K线颜色红色=涨,绿色=跌
- ✅ 完整显示OHLC信息开高低收
- ✅ 保留上下沿趋势线(更醒目的样式)
- ✅ 移除 `--show-high-low` 参数K线已包含高低价
### 使用方法
```bash
# 生成K线图默认
python scripts/plot_converging_triangles.py
# K线图 + 详细模式
python scripts/plot_converging_triangles.py --show-details
# 完整流水线
python scripts/pipeline_converging_triangle.py
```
详见:`docs/K线图说明.md`
---
## 2. 每日最佳股票报告 📈
### 功能说明
- 最近500天每个交易日自动筛选强度分最高的股票
- 输出完整列表和CSV文件
- 统计哪些股票最常被选为最佳
### 输出文件
- `outputs/converging_triangles/daily_best.csv`
- `outputs/converging_triangles/run_log_*.txt`
### 示例输出
```
共 330 个交易日检测到收敛三角形:
日期 股票代码 股票名称 强度↑ 强度↓ 方向 收敛比
20260120 SH600475 华光环能 0.7071 0.2071 up 0.002
20260119 SH600475 华光环能 0.7067 0.2067 up 0.005
...
股票被选为每日最佳的次数排行:
SZ002343 慈文传媒: 17 次
SH603618 杭电股份: 14 次
...
```
---
## 3. 边界线拟合配置 🔧
### 修改内容
- ✅ 绘图默认使用**高低价拟合**(从收盘价改回)
-`pipeline_converging_triangle.py`: `default="hl"`
-`plot_converging_triangles.py`: `default="hl"`
### 说明
- **检测算法**始终使用高低价枢轴点基于High/Low
- **绘图展示**:可选高低价或收盘价
- **推荐**:使用高低价(与检测一致,更精确)
---
## 4. 性能优化尝试v2版本
### 优化思路
预计算整个时间序列的枢轴点标记矩阵,避免滑动窗口重复计算。
### 实测结果
- v1当前: **2.56 秒**
- v2预计算: 5.15 秒 ❌
### 结论
- v1 性能已经很好,无需进一步优化
- v2 因为实现复杂度和首次编译开销,反而变慢
- **保持使用 v1 版本**(稳定快速)
### 配置
```python
# triangle_config.py
USE_V2_OPTIMIZATION = False # 使用v1推荐
REALTIME_MODE = True # 实时模式
```
---
## 之前的问题(已解决)
### 问题:上/下沿线,有些点没有碰到线的边缘
![](images/2026-01-28-11-16-46.png)
![](images/2026-01-28-11-16-56.png)
#### 原因
- 枢轴点与边界拟合使用的是 High/Low高低价而主图只绘制了收盘价曲线出现长上影/下影时会放大偏离感。
- 采用"锚点+覆盖率"的边界拟合法,目标是包络多数枢轴点而非贴合收盘价,因此线会更保守、更远离收盘价。
#### 解决方案
![](images/2026-01-28-15-56-12.png)
已在绘图脚本加入仅影响展示的两类开关(不改变检测结果):
- ~~显示日内高低价范围:`--show-high-low`~~已移除K线图自带
- 绘图时将边界线拟合源切换为收盘价:`--plot-boundary-source close`
示例:
```bash
python scripts/plot_converging_triangles.py --plot-boundary-source close
```
#### 后续发现的问题(已修复)
**问题1拟合贴合度显示为0**
修复:重新计算基于收盘价的拟合贴合度
**问题2枢轴点显示位置不匹配**
修复根据数据源选择枢轴点标记的Y坐标
**问题3流水线脚本缺少参数支持**
修复:添加参数并传递
---
## 批量检测算法优化
![](images/2026-01-28-17-13-37.png)
![](images/2026-01-28-17-22-42.png)
### 性能表现
- **原始版本**92秒
- **v1优化版****2.56秒**首次需要3-5秒编译
- **提升****35倍** 🚀
### 检测规模
- 108只股票 × 500天 = **54,000个检测点**
- 检测到有效三角形:**18,004个**约33%
- 有三角形的交易日:**330天**500天中
### 使用方法
```bash
# 运行批量检测(自动保存日志和每日最佳)
python scripts/run_converging_triangle.py
# 查看输出
# - outputs/converging_triangles/run_log_YYYYMMDD_HHMMSS.txt
# - outputs/converging_triangles/daily_best.csv
```