Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zengbin93
czsc
提交
b2ae91f9
C
czsc
项目概览
zengbin93
/
czsc
通知
23
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
czsc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b2ae91f9
编写于
8月 23, 2020
作者:
Z
zengbin93
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
0.5.3 优化笔的识别
上级
b7d60e92
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
15 deletion
+34
-15
czsc/analyze.py
czsc/analyze.py
+34
-15
未找到文件。
czsc/analyze.py
浏览文件 @
b2ae91f9
...
...
@@ -124,15 +124,21 @@ def find_zs(points):
return
k_zs
def
has_gap
(
k1
,
k2
):
"""判断 k1, k2 之间是否有缺口"""
assert
k2
[
'dt'
]
>
k1
[
'dt'
]
if
k1
[
'high'
]
<
k2
[
'low'
]
*
0.998
or
k2
[
'high'
]
<
k1
[
'low'
]
*
0.998
:
return
True
else
:
return
False
class
KlineAnalyze
:
def
__init__
(
self
,
kline
,
name
=
"本级别"
,
min_bi_k
=
5
,
bi_mode
=
"old"
,
max_raw_len
=
10000
,
ma_params
=
(
5
,
20
,
120
),
verbose
=
False
):
def
__init__
(
self
,
kline
,
name
=
"本级别"
,
bi_mode
=
"old"
,
max_raw_len
=
10000
,
ma_params
=
(
5
,
20
,
120
),
verbose
=
False
):
"""
:param kline: list or pd.DataFrame
:param name: str
:param min_bi_k: int
笔内部的最少K线数量
:param bi_mode: str
new 新笔;old 老笔;默认值为 old
:param max_raw_len: int
...
...
@@ -143,7 +149,6 @@ class KlineAnalyze:
"""
self
.
name
=
name
self
.
verbose
=
verbose
self
.
min_bi_k
=
min_bi_k
self
.
bi_mode
=
bi_mode
self
.
max_raw_len
=
max_raw_len
self
.
ma_params
=
ma_params
...
...
@@ -296,6 +301,12 @@ class KlineAnalyze:
i
=
1
while
i
<=
len
(
kn
)
-
2
:
k1
,
k2
,
k3
=
kn
[
i
-
1
:
i
+
2
]
fx_elements
=
[
k1
,
k2
,
k3
]
if
has_gap
(
k1
,
k2
):
fx_elements
.
pop
(
0
)
if
has_gap
(
k2
,
k3
):
fx_elements
.
pop
(
-
1
)
if
k1
[
'high'
]
<
k2
[
'high'
]
>
k3
[
'high'
]:
if
self
.
verbose
:
...
...
@@ -304,8 +315,10 @@ class KlineAnalyze:
"dt"
:
k2
[
'dt'
],
"fx_mark"
:
"g"
,
"fx"
:
k2
[
'high'
],
"start_dt"
:
k1
[
'dt'
],
"end_dt"
:
k3
[
'dt'
],
"fx_high"
:
k2
[
'high'
],
"fx_low"
:
min
(
k1
[
'low'
],
k3
[
'low'
]),
"fx_low"
:
min
(
[
x
[
'low'
]
for
x
in
fx_elements
]),
}
self
.
fx_list
.
append
(
fx
)
...
...
@@ -316,7 +329,9 @@ class KlineAnalyze:
"dt"
:
k2
[
'dt'
],
"fx_mark"
:
"d"
,
"fx"
:
k2
[
'low'
],
"fx_high"
:
max
(
k1
[
'high'
],
k3
[
'high'
]),
"start_dt"
:
k1
[
'dt'
],
"end_dt"
:
k3
[
'dt'
],
"fx_high"
:
max
([
x
[
'high'
]
for
x
in
fx_elements
]),
"fx_low"
:
k2
[
'low'
],
}
self
.
fx_list
.
append
(
fx
)
...
...
@@ -381,14 +396,18 @@ class KlineAnalyze:
print
(
"笔标记移动:from {} to {}"
.
format
(
self
.
bi_list
[
-
1
],
bi
))
self
.
bi_list
[
-
1
]
=
bi
else
:
kn_inside
=
[
x
for
x
in
right_kn
if
last_bi
[
'dt'
]
<=
x
[
'dt'
]
<=
bi
[
'dt'
]]
if
len
(
kn_inside
)
>=
self
.
min_bi_k
:
# 确保相邻两个顶底之间不存在包含关系
if
(
last_bi
[
'fx_mark'
]
==
'g'
and
bi
[
'fx_low'
]
<
last_bi
[
'fx_low'
]
and
bi
[
'fx_high'
]
<
last_bi
[
'fx_high'
])
or
\
(
last_bi
[
'fx_mark'
]
==
'd'
and
bi
[
'fx_high'
]
>
last_bi
[
'fx_high'
]
and
bi
[
'fx_low'
]
>
last_bi
[
'fx_low'
]):
if
self
.
verbose
:
print
(
"新增笔标记:{}"
.
format
(
bi
))
self
.
bi_list
.
append
(
bi
)
kn_inside
=
[
x
for
x
in
right_kn
if
last_bi
[
'end_dt'
]
<
x
[
'dt'
]
<
bi
[
'start_dt'
]]
if
len
(
kn_inside
)
<=
0
:
continue
# 确保相邻两个顶底之间不存在包含关系
if
(
last_bi
[
'fx_mark'
]
==
'g'
and
bi
[
'fx_low'
]
<
last_bi
[
'fx_low'
]
and
bi
[
'fx_high'
]
<
last_bi
[
'fx_high'
])
or
\
(
last_bi
[
'fx_mark'
]
==
'd'
and
bi
[
'fx_high'
]
>
last_bi
[
'fx_high'
]
and
bi
[
'fx_low'
]
>
last_bi
[
'fx_low'
]):
if
self
.
verbose
:
print
(
"新增笔标记:{}"
.
format
(
bi
))
self
.
bi_list
.
append
(
bi
)
if
(
self
.
bi_list
[
-
1
][
'fx_mark'
]
==
'd'
and
self
.
kline_new
[
-
1
][
'low'
]
<
self
.
bi_list
[
-
1
][
'bi'
])
\
or
(
self
.
bi_list
[
-
1
][
'fx_mark'
]
==
'g'
and
self
.
kline_new
[
-
1
][
'high'
]
>
self
.
bi_list
[
-
1
][
'bi'
]):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录