缠论段源码
时间: 2023-07-05 18:11:43 浏览: 84
缠论段是缠论理论中的一个重要概念,表示股价走势中的一个相对较长的趋势段落。缠论段由一组相邻的笔组成,方向相同的笔合并为一个段。
以下是一个基于Python实现的缠论段的代码示例:
```python
def get_segment_direction(pens):
"""
判断段的方向,向上段(1)或向下段(-1)
"""
direction = 0
if len(pens) >= 2:
if pens[-1][2] == pens[-2][2]:
direction = pens[-1][2]
return direction
def get_segments(pens):
"""
获取段的列表
"""
segments = []
segment_start = 0
segment_direction = 0
for i in range(1, len(pens)):
direction = get_segment_direction(pens[:i+1])
if direction != segment_direction:
if segment_start > 0:
segments.append((segment_start, i, segment_direction))
segment_start = i
segment_direction = direction
if segment_start > 0:
segments.append((segment_start, len(pens)-1, segment_direction))
return segments
```
这段代码实现了获取股价走势中的段的列表的功能。通过传入笔的列表,该函数会遍历整个列表,根据相邻的笔的方向计算出段的方向,然后将相同方向的笔合并为一个段,并返回段的列表。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)