褚宏光 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

1.8 KiB
Raw Blame History

使用说明

快速启动

.\.venv\Scripts\Activate.ps1
python scripts/run_converging_triangle.py

1. 创建与激活虚拟环境

# 创建环境(首次)
python -m venv .venv

# 激活环境
.\.venv\Scripts\Activate.ps1

2. 安装依赖

pip install numpy pandas matplotlib

3. 运行脚本

收敛三角形批量检测(主脚本)

python scripts/run_converging_triangle.py

输出:

  • outputs/converging_triangles/all_results.csv - 全部检测结果
  • outputs/converging_triangles/strong_breakout_up.csv - 高强度向上突破
  • outputs/converging_triangles/strong_breakout_down.csv - 高强度向下突破

对称三角形检测(单点检测)

python scripts/run_sym_triangle_pkl.py

输出:

  • outputs/sym_triangles/*.png - 各股票图表
  • outputs/sym_triangles/summary.csv - 汇总表

4. 参数调整

编辑 scripts/run_converging_triangle.py 顶部的参数区:

PARAMS = ConvergingTriangleParams(
    window=400,           # 分析窗口大小
    pivot_k=20,           # 枢轴点检测窗口
    shrink_ratio=0.8,     # 收敛比阈值
    # ...
)

RECENT_DAYS = 500         # 计算最近 N 天None=全部历史)
ONLY_VALID = True         # 只输出有效三角形

5. 数据格式

数据文件位于 data/ 目录,格式为 pkl

{
    'mtx': ndarray (n_stocks, n_days),  # 数据矩阵
    'dtes': ndarray (n_days,),          # 日期 (20050104)
    'tkrs': ndarray (n_stocks,),        # 股票代码 (SH600000)
    'tkrs_name': ndarray (n_stocks,),   # 股票名称
}

6. 备注

  • 关闭环境:deactivate
  • 权限问题PowerShell
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser