- Introduced a new API for converging triangle detection, including the main function `detect_matrix()` for batch processing of stock data. - Added detailed documentation for the API, covering usage examples, parameter configurations, and output structures. - Created new markdown files for reference and usage instructions, enhancing the overall documentation quality. New files: - `src/triangle_detector_api.py`: Core API implementation. - `docs/triangle_api_reference.md`: Comprehensive API reference documentation. - `discuss/20260129-三角形强度.md`: Documentation for triangle strength detection functions. - `docs/2026-01-29_三角形数据_server.md`: Detailed usage of the triangle detection functions.
111 lines
3.4 KiB
Markdown
111 lines
3.4 KiB
Markdown
## 1. `三角形强度()` - 全市场批量筛选
|
||
|
||
**作用**:对全市场所有股票、所有日期进行批量检测,返回强度矩阵,用于筛选和排序。
|
||
|
||
**入参**:
|
||
| 参数 | 类型 | 默认值 | 说明 |
|
||
|-----|------|--------|------|
|
||
| `window` | int | 240 | 检测窗口(交易日) |
|
||
| `min_convergence` | float | 0.45 | 最小收敛比例(末端/起始宽度) |
|
||
| `breakout_threshold` | float | 0.005 | 突破阈值(0.5%) |
|
||
| `volume_multiplier` | float | 1.5 | 放量确认倍数 |
|
||
| `start_day` | int | -1 | 起始日索引(-1=自动) |
|
||
| `end_day` | int | -1 | 结束日索引(-1=自动) |
|
||
|
||
**返回值**:
|
||
```python
|
||
np.ndarray # shape: (n_stocks, n_days)
|
||
```
|
||
- 正值 `+0 ~ +1`:向上突破/潜力,值越大越强
|
||
- 负值 `-1 ~ -0`:向下突破/潜力,绝对值越大越强
|
||
- `NaN`:无有效形态
|
||
|
||
**使用场景**:
|
||
```python
|
||
强度 = 三角形强度()
|
||
|
||
# 筛选最新一天强向上的股票
|
||
强向上 = 强度[:, -1] > 0.5
|
||
|
||
# 按强度排序
|
||
排名 = np.argsort(强度[:, -1])[::-1]
|
||
```
|
||
|
||
---
|
||
|
||
## 2. `三角形详情(ticker)` - 单股票详情
|
||
|
||
**作用**:对单只股票进行检测,返回完整详情(强度分量、几何属性、图表数据),用于展示和分析。
|
||
|
||
**入参**:
|
||
| 参数 | 类型 | 默认值 | 说明 |
|
||
|-----|------|--------|------|
|
||
| `ticker` | str | 必填 | 股票代码,如 `"SH600519"` |
|
||
| `window` | int | 240 | 检测窗口 |
|
||
| `min_convergence` | float | 0.45 | 最小收敛比例 |
|
||
| `breakout_threshold` | float | 0.005 | 突破阈值 |
|
||
| `volume_multiplier` | float | 1.5 | 放量倍数 |
|
||
| `display_days` | int | 300 | 图表显示天数 |
|
||
|
||
**返回值**:`TriangleDetail` 对象
|
||
|
||
| 字段 | 类型 | 说明 |
|
||
|-----|------|------|
|
||
| `strength` | float | 综合强度 (-1 ~ +1) |
|
||
| `is_valid` | bool | 是否有效形态 |
|
||
| `direction` | str | `"up"` / `"down"` / `"none"` |
|
||
| `strength_up` | float | 向上强度原始值 (0~1) |
|
||
| `strength_down` | float | 向下强度原始值 (0~1) |
|
||
| `convergence_score` | float | 收敛分 (0~1) |
|
||
| `volume_score` | float | 成交量分 (0~1) |
|
||
| `fitting_score` | float | 拟合分 (0~1) |
|
||
| `width_ratio` | float | 收敛比例 |
|
||
| `upper_slope` | float | 上沿斜率 |
|
||
| `lower_slope` | float | 下沿斜率 |
|
||
| `touches_upper` | int | 触碰上沿次数 |
|
||
| `touches_lower` | int | 触碰下沿次数 |
|
||
| `volume_confirmed` | bool | 成交量是否确认 |
|
||
| `chart_data` | dict | 图表数据(ECharts 格式) |
|
||
|
||
**`chart_data` 结构**:
|
||
```python
|
||
{
|
||
'dates': [20260101, 20260102, ...], # 日期
|
||
'candlestick': [[o,c,l,h], ...], # K线数据
|
||
'upper_line': [[x1,y1], [x2,y2]], # 上沿线
|
||
'lower_line': [[x1,y1], [x2,y2]], # 下沿线
|
||
'detection_window': [start, end], # 检测窗口
|
||
'ticker': "SH600519",
|
||
'strength': 0.65,
|
||
'direction': "up",
|
||
}
|
||
```
|
||
|
||
**使用场景**:
|
||
```python
|
||
详情 = 三角形详情("SH600519")
|
||
|
||
# 查看结果
|
||
print(f"强度: {详情.strength}")
|
||
print(f"方向: {详情.direction}")
|
||
print(f"收敛度: {详情.width_ratio}")
|
||
|
||
# 前端绑定
|
||
图表配置 = 详情.chart_data
|
||
```
|
||
|
||
---
|
||
|
||
## 典型工作流
|
||
|
||
```python
|
||
# 1. 批量筛选
|
||
强度 = 三角形强度()
|
||
目标股票索引 = np.where(强度[:, -1] > 0.5)[0]
|
||
|
||
# 2. 获取详情
|
||
tkrs = g.load_pkl()['tkrs']
|
||
for idx in 目标股票索引[:10]:
|
||
详情 = 三角形详情(tkrs[idx])
|
||
print(f"{tkrs[idx]}: {详情.strength:.2f}, {详情.direction}")
|
||
``` |