Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zengbin93
czsc
提交
435aef61
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 搜索 >>
提交
435aef61
编写于
4月 24, 2020
作者:
Z
zengbin93
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
0.3.1 线段、笔识别过程开发完成
上级
79819100
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
57 addition
and
27 deletion
+57
-27
chan/analyze.py
chan/analyze.py
+57
-27
未找到文件。
chan/analyze.py
浏览文件 @
435aef61
...
...
@@ -24,6 +24,7 @@ def is_bei_chi(ka, zs1, zs2, direction="down", mode="bi"):
bi 判断两笔之间是否存在背驰
:return:
"""
assert
zs1
[
0
]
>
zs2
[
0
],
"zs1 必须是最近的走势,用于比较;zs2 必须是较前的走势,被比较。"
df
=
pd
.
DataFrame
(
ka
.
kline
)
df
=
macd
(
df
)
k1
=
df
[(
df
[
'dt'
]
>=
zs1
[
0
])
&
(
df
[
'dt'
]
<=
zs1
[
1
])]
...
...
@@ -283,10 +284,18 @@ class KlineAnalyze(object):
return
bi
def
__handle_last_bi
(
self
,
bi
):
pass
"""处理最后一个笔标记"""
last_bi
=
bi
[
-
1
]
seq
=
[
x
for
x
in
self
.
kline_new
if
x
[
'dt'
]
>=
last_bi
[
'dt'
]]
sor
=
sorted
(
deepcopy
(
seq
),
key
=
lambda
x
:
x
[
'close'
],
reverse
=
False
)
if
(
last_bi
[
'fx_mark'
]
==
'd'
and
sor
[
0
][
'close'
]
<
last_bi
[
'bi'
])
\
or
(
last_bi
[
'fx_mark'
]
==
'g'
and
sor
[
-
1
][
'close'
]
>
last_bi
[
'bi'
]):
bi
.
pop
(
-
1
)
return
bi
def
_find_bi
(
self
):
bi
=
self
.
__handle_hist_bi
()
bi
=
self
.
__handle_last_bi
(
bi
)
dts
=
[
x
[
"dt"
]
for
x
in
bi
]
for
k
in
self
.
kline_new
:
if
k
[
'dt'
]
in
dts
:
...
...
@@ -325,39 +334,60 @@ class KlineAnalyze(object):
# 一线段内部至少三笔
if
len
(
bi_m
)
>=
4
:
xd
.
append
(
k
)
return
xd
# 后处理:在任一线段内部,底分型一定是最低点,顶分型一定是最高点
xd_new
=
[]
for
i
in
range
(
len
(
xd
)):
if
i
==
0
:
xd2
=
xd
[
i
+
1
]
bi_m
=
[
x
for
x
in
self
.
bi
if
x
[
'dt'
]
<=
xd2
[
'dt'
]]
elif
i
==
len
(
xd
)
-
1
:
xd1
=
xd
[
i
-
1
]
bi_m
=
[
x
for
x
in
self
.
bi
if
x
[
'dt'
]
>=
xd1
[
'dt'
]]
else
:
xd1
,
xd2
=
xd
[
i
-
1
],
xd
[
i
+
1
]
bi_m
=
[
x
for
x
in
self
.
bi
if
xd1
[
'dt'
]
<=
x
[
'dt'
]
<=
xd2
[
'dt'
]]
xd0
=
xd
[
i
]
if
xd0
[
'fx_mark'
]
==
'd'
:
bi_m
=
sorted
(
bi_m
,
key
=
lambda
x
:
x
[
'bi'
],
reverse
=
False
)
elif
xd0
[
'fx_mark'
]
==
'g'
:
bi_m
=
sorted
(
bi_m
,
key
=
lambda
x
:
x
[
'bi'
],
reverse
=
True
)
else
:
raise
ValueError
new
=
deepcopy
(
bi_m
[
0
])
def
__handle_last_xd
(
self
,
xd
):
"""处理最后一个线段标记"""
last_xd
=
xd
[
-
1
]
bi_seq
=
[
x
for
x
in
self
.
bi
if
x
[
'dt'
]
>=
last_xd
[
'dt'
]]
bi_sor
=
sorted
(
deepcopy
(
bi_seq
),
key
=
lambda
x
:
x
[
'bi'
],
reverse
=
False
)
# 最后一个线段标记为底,且该标记后笔序列的最小值小于该线段标记,移动
if
last_xd
[
'fx_mark'
]
==
'd'
and
bi_sor
[
0
][
'bi'
]
<
last_xd
[
'xd'
]:
xd
.
pop
(
-
1
)
new
=
deepcopy
(
bi_sor
[
0
])
new
[
'xd'
]
=
new
[
'bi'
]
del
new
[
'bi'
]
xd_new
.
append
(
new
)
return
xd
del
new
[
"bi"
]
xd
.
append
(
new
)
def
__handle_last_xd
(
self
,
xd_v
):
pass
# 最后一个线段标记为顶,且该标记后笔序列的最大值大于该线段标记,移动
if
last_xd
[
'fx_mark'
]
==
'g'
and
bi_sor
[
-
1
][
'bi'
]
>
last_xd
[
'xd'
]:
xd
.
pop
(
-
1
)
new
=
deepcopy
(
bi_sor
[
-
1
])
new
[
'xd'
]
=
new
[
'bi'
]
del
new
[
"bi"
]
xd
.
append
(
new
)
# 最后一个线段标记为底,且与该标记后笔序列的最大值之间满足线段成立的条件,新增一个线段标记
if
last_xd
[
'fx_mark'
]
==
'd'
:
bi_m
=
[
x
for
x
in
self
.
bi
if
bi_sor
[
-
1
][
'dt'
]
>=
x
[
'dt'
]
>=
last_xd
[
'dt'
]]
# 线段条件:内部有三笔,且最后一笔新高背驰
if
len
(
bi_m
)
>
4
:
zs1
=
[
bi_m
[
-
2
][
'dt'
],
bi_m
[
-
1
][
'dt'
]]
zs2
=
[
bi_m
[
-
4
][
'dt'
],
bi_m
[
-
3
][
'dt'
]]
if
is_bei_chi
(
self
,
zs1
,
zs2
,
mode
=
'bi'
):
new
=
deepcopy
(
bi_sor
[
-
1
])
new
[
'xd'
]
=
new
[
'bi'
]
del
new
[
"bi"
]
xd
.
append
(
new
)
# 最后一个线段标记为顶,且与该标记后笔序列的最小值之间满足线段成立的条件,新增一个线段标记
if
last_xd
[
'fx_mark'
]
==
'g'
:
bi_m
=
[
x
for
x
in
self
.
bi
if
bi_sor
[
0
][
'dt'
]
>=
x
[
'dt'
]
>=
last_xd
[
'dt'
]]
# 向下线段条件:内部有三笔,且最后一笔新低背驰
if
len
(
bi_m
)
>
4
:
zs1
=
[
bi_m
[
-
2
][
'dt'
],
bi_m
[
-
1
][
'dt'
]]
zs2
=
[
bi_m
[
-
4
][
'dt'
],
bi_m
[
-
3
][
'dt'
]]
if
is_bei_chi
(
self
,
zs1
,
zs2
,
mode
=
'bi'
):
new
=
deepcopy
(
bi_sor
[
0
])
new
[
'xd'
]
=
new
[
'bi'
]
del
new
[
"bi"
]
xd
.
append
(
new
)
return
xd
def
_find_xd
(
self
):
try
:
xd
=
self
.
__handle_hist_xd
()
xd
=
self
.
__handle_last_xd
(
xd
)
dts
=
[
x
[
"dt"
]
for
x
in
xd
]
for
k
in
self
.
kline_new
:
if
k
[
'dt'
]
in
dts
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录