Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zengbin93
czsc
提交
d0a388a4
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 搜索 >>
提交
d0a388a4
编写于
9月 28, 2020
作者:
Z
zengbin93
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
0.5.6 update
上级
25c0b8d3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
169 addition
and
360 deletion
+169
-360
czsc/analyze.py
czsc/analyze.py
+160
-2
czsc/signals.py
czsc/signals.py
+0
-158
czsc/utils.py
czsc/utils.py
+8
-199
test/test_signals.py
test/test_signals.py
+1
-1
未找到文件。
czsc/analyze.py
浏览文件 @
d0a388a4
...
...
@@ -12,7 +12,7 @@ except ImportError:
warnings
.
warn
(
ta_lib_hint
)
import
pandas
as
pd
import
numpy
as
np
from
czsc.utils
import
plot_ka
from
czsc.utils
import
ka_to_image
def
find_zs
(
points
):
"""输入笔或线段标记点,输出中枢识别结果"""
...
...
@@ -277,6 +277,164 @@ def get_potential_xd(bi_points):
return
xd_p
def
check_jing
(
fd1
,
fd2
,
fd3
,
fd4
,
fd5
):
"""检查最近5个分段走势是否构成井
井的定义:
12345,五段,是构造井的基本形态,形成井的位置肯定是5,而5出井的
前提条件是对于向上5至少比3和1其中之一高,向下反过来; 并且,234
构成一个中枢。
井只有两类,大井和小井(以向上为例):
大井对应的形式是:12345向上,5最高3次之1最低,力度上1大于3,3大于5;
小井对应的形式是:
1:12345向上,3最高5次之1最低,力度上5的力度比1小,注意这时候
不需要再考虑5和3的关系了,因为5比3低,所以不需要考虑力度。
2:12345向上,5最高3次之1最低,力度上1大于5,5大于3。
小井的构造,关键是满足5一定至少大于1、3中的一个。
注意有一种情况不归为井:就是12345向上,1的力度最小,5的力度次之,3的力度最大此类不算井,
因为345后面必然还有走势在67的时候才能再判断,个中道理各位好好体会。
fd 为 dict 对象,表示一段走势,可以是笔、线段,样例如下:
fd = {
"start_dt": "",
"end_dt": "",
"power": 0, # 力度
"direction": "up",
"high": 0,
"low": 0,
"mode": "bi"
}
假定最近一段走势为第N段;则 fd1 为第N-4段走势, fd2为第N-3段走势,
fd3为第N-2段走势, fd4为第N-1段走势, fd5为第N段走势
"""
assert
fd1
[
'direction'
]
==
fd3
[
'direction'
]
==
fd5
[
'direction'
]
assert
fd2
[
'direction'
]
==
fd4
[
'direction'
]
direction
=
fd1
[
'direction'
]
zs_g
=
min
(
fd2
[
'high'
],
fd3
[
'high'
],
fd4
[
'high'
])
zs_d
=
max
(
fd2
[
'low'
],
fd3
[
'low'
],
fd4
[
'low'
])
jing
=
{
"jing"
:
"没有出井"
,
"notes"
:
""
}
# 1的力度最小,5的力度次之,3的力度最大,此类不算井
if
fd1
[
'power'
]
<
fd5
[
'power'
]
<
fd3
[
'power'
]:
jing
[
'notes'
]
=
"1的力度最小,5的力度次之,3的力度最大,此类不算井"
return
jing
if
zs_d
<
zs_g
:
# 234有中枢的情况
if
direction
==
'up'
and
fd5
[
"high"
]
>
min
(
fd3
[
'high'
],
fd1
[
'high'
]):
# 大井对应的形式是:12345向上,5最高3次之1最低,力度上1大于3,3大于5
if
fd5
[
"high"
]
>
fd3
[
'high'
]
>
fd1
[
'high'
]
and
fd5
[
'power'
]
<
fd3
[
'power'
]
<
fd1
[
'power'
]:
jing
=
{
"jing"
:
"向上大井"
,
"notes"
:
"12345向上,5最高3次之1最低,力度上1大于3,3大于5"
}
# 第一种小井:12345向上,3最高5次之1最低,力度上5的力度比1小
if
fd1
[
'high'
]
<
fd5
[
'high'
]
<
fd3
[
'high'
]
and
fd5
[
'power'
]
<
fd1
[
'power'
]:
jing
=
{
"jing"
:
"向上小井"
,
"notes"
:
"12345向上,3最高5次之1最低,力度上5的力度比1小"
}
# 第二种小井:12345向上,5最高3次之1最低,力度上1大于5,5大于3
if
fd5
[
"high"
]
>
fd3
[
'high'
]
>
fd1
[
'high'
]
and
fd1
[
'power'
]
>
fd5
[
'power'
]
>
fd3
[
'power'
]:
jing
=
{
"jing"
:
"向上小井"
,
"notes"
:
"12345向上,5最高3次之1最低,力度上1大于5,5大于3"
}
if
direction
==
'down'
and
fd5
[
"low"
]
<
max
(
fd3
[
'low'
],
fd1
[
'low'
]):
# 大井对应的形式是:12345向下,5最低3次之1最高,力度上1大于3,3大于5
if
fd5
[
'low'
]
<
fd3
[
'low'
]
<
fd1
[
'low'
]
and
fd5
[
'power'
]
<
fd3
[
'power'
]
<
fd1
[
'power'
]:
jing
=
{
"jing"
:
"向下大井"
,
"notes"
:
"12345向下,5最低3次之1最高,力度上1大于3,3大于5"
}
# 第一种小井:12345向下,3最低5次之1最高,力度上5的力度比1小
if
fd1
[
"low"
]
>
fd5
[
'low'
]
>
fd3
[
'low'
]
and
fd5
[
'power'
]
<
fd1
[
'power'
]:
jing
=
{
"jing"
:
"向下小井"
,
"notes"
:
"12345向下,3最低5次之1最高,力度上5的力度比1小"
}
# 第二种小井:12345向下,5最低3次之1最高,力度上1大于5,5大于3
if
fd5
[
'low'
]
<
fd3
[
'low'
]
<
fd1
[
'low'
]
and
fd1
[
'power'
]
>
fd5
[
'power'
]
>
fd3
[
'power'
]:
jing
=
{
"jing"
:
"向下小井"
,
"notes"
:
"12345向下,5最低3次之1最高,力度上1大于5,5大于3"
}
else
:
# 第三种小井:12345类趋势,力度依次降低,可以看成小井
if
fd1
[
'power'
]
>
fd3
[
'power'
]
>
fd5
[
'power'
]:
if
direction
==
'up'
and
fd5
[
"high"
]
>
fd3
[
'high'
]
>
fd1
[
'high'
]:
jing
=
{
"jing"
:
"向上小井"
,
"notes"
:
"12345类上涨趋势,力度依次降低"
}
if
direction
==
'down'
and
fd5
[
"low"
]
<
fd3
[
'low'
]
<
fd1
[
'low'
]:
jing
=
{
"jing"
:
"向下小井"
,
"notes"
:
"12345类下跌趋势,力度依次降低"
}
return
jing
def
check_bei_chi
(
fd1
,
fd2
,
fd3
,
fd4
,
fd5
):
"""检查最近5个分段走势是否有背驰
fd 为 dict 对象,表示一段走势,可以是笔、线段,样例如下:
fd = {
"start_dt": "",
"end_dt": "",
"power": 0, # 力度
"direction": "up",
"high": 0,
"low": 0,
"mode": "bi"
}
"""
assert
fd1
[
'direction'
]
==
fd3
[
'direction'
]
==
fd5
[
'direction'
]
assert
fd2
[
'direction'
]
==
fd4
[
'direction'
]
direction
=
fd1
[
'direction'
]
zs_g
=
min
(
fd2
[
'high'
],
fd3
[
'high'
],
fd4
[
'high'
])
zs_d
=
max
(
fd2
[
'low'
],
fd3
[
'low'
],
fd4
[
'low'
])
bc
=
{
"bc"
:
"没有背驰"
,
"notes"
:
""
}
if
max
(
fd5
[
'power'
],
fd3
[
'power'
],
fd1
[
'power'
])
==
fd5
[
'power'
]:
bc
=
{
"bc"
:
"没有背驰"
,
"notes"
:
"5的力度最大,没有背驰"
}
return
bc
if
zs_d
<
zs_g
:
if
fd5
[
'power'
]
<
fd1
[
'power'
]:
if
direction
==
'up'
and
fd5
[
"high"
]
>
min
(
fd3
[
'high'
],
fd1
[
'high'
]):
bc
=
{
"bc"
:
"向上趋势背驰"
,
"notes"
:
"12345向上,234构成中枢,5最高,力度上1大于5"
}
if
direction
==
'down'
and
fd5
[
"low"
]
<
max
(
fd3
[
'low'
],
fd1
[
'low'
]):
bc
=
{
"bc"
:
"向下趋势背驰"
,
"notes"
:
"12345向下,234构成中枢,5最低,力度上1大于5"
}
else
:
if
fd5
[
'power'
]
<
fd3
[
'power'
]:
if
direction
==
'up'
and
fd5
[
"high"
]
>
fd3
[
'high'
]:
bc
=
{
"bc"
:
"向上盘整背驰"
,
"notes"
:
"12345向上,234不构成中枢,5最高,力度上1大于5"
}
if
direction
==
'down'
and
fd5
[
"low"
]
<
fd3
[
'low'
]:
bc
=
{
"bc"
:
"向下盘整背驰"
,
"notes"
:
"12345向下,234不构成中枢,5最低,力度上1大于5"
}
return
bc
def
check_third_bs
(
fd1
,
fd2
,
fd3
,
fd4
,
fd5
):
"""输入5段走势,判断是否存在第三类买卖点"""
zs_d
=
max
(
fd1
[
'low'
],
fd2
[
'low'
],
fd3
[
'low'
])
zs_g
=
min
(
fd1
[
'high'
],
fd2
[
'high'
],
fd3
[
'high'
])
third_bs
=
{
"third_bs"
:
"没有第三类买卖点"
,
"notes"
:
""
}
if
max
(
fd1
[
'power'
],
fd2
[
'power'
],
fd3
[
'power'
],
fd4
[
'power'
],
fd5
[
'power'
])
!=
fd4
[
'power'
]:
third_bs
=
{
"third_bs"
:
"没有第三类买卖点"
,
"notes"
:
"第四段不是力度最大的段"
}
return
third_bs
if
zs_g
<
zs_d
:
third_bs
=
{
"third_bs"
:
"没有第三类买卖点"
,
"notes"
:
"前三段不构成中枢,无第三类买卖点"
}
else
:
if
fd4
[
'low'
]
<
zs_d
and
fd5
[
'high'
]
<
zs_d
:
third_bs
=
{
"third_bs"
:
"三卖"
,
"notes"
:
"前三段构成中枢,第四段向下离开,第五段不回中枢"
}
if
fd4
[
'high'
]
>
zs_g
and
fd5
[
'low'
]
>
zs_g
:
third_bs
=
{
"third_bs"
:
"三买"
,
"notes"
:
"前三段构成中枢,第四段向上离开,第五段不回中枢"
}
return
third_bs
class
KlineAnalyze
:
def
__init__
(
self
,
kline
,
name
=
"本级别"
,
bi_mode
=
"new"
,
max_xd_len
=
20
,
ma_params
=
(
5
,
34
,
120
),
verbose
=
False
):
"""
...
...
@@ -739,7 +897,7 @@ class KlineAnalyze:
图片分辨率
:return:
"""
plot_ka
(
self
,
file_image
=
file_image
,
mav
=
mav
,
max_k_count
=
max_k_count
,
dpi
=
dpi
)
ka_to_image
(
self
,
file_image
=
file_image
,
mav
=
mav
,
max_k_count
=
max_k_count
,
dpi
=
dpi
)
def
is_bei_chi
(
self
,
zs1
,
zs2
,
mode
=
"bi"
,
adjust
=
0.9
,
last_index
:
int
=
None
):
"""判断 zs1 对 zs2 是否有背驰
...
...
czsc/signals.py
浏览文件 @
d0a388a4
# coding: utf-8
from
.analyze
import
KlineAnalyze
,
find_zs
def
check_jing
(
fd1
,
fd2
,
fd3
,
fd4
,
fd5
):
"""检查最近5个分段走势是否构成井
井的定义:
12345,五段,是构造井的基本形态,形成井的位置肯定是5,而5出井的
前提条件是对于向上5至少比3和1其中之一高,向下反过来; 并且,234
构成一个中枢。
井只有两类,大井和小井(以向上为例):
大井对应的形式是:12345向上,5最高3次之1最低,力度上1大于3,3大于5;
小井对应的形式是:
1:12345向上,3最高5次之1最低,力度上5的力度比1小,注意这时候
不需要再考虑5和3的关系了,因为5比3低,所以不需要考虑力度。
2:12345向上,5最高3次之1最低,力度上1大于5,5大于3。
小井的构造,关键是满足5一定至少大于1、3中的一个。
注意有一种情况不归为井:就是12345向上,1的力度最小,5的力度次之,3的力度最大此类不算井,
因为345后面必然还有走势在67的时候才能再判断,个中道理各位好好体会。
fd 为 dict 对象,表示一段走势,可以是笔、线段,样例如下:
fd = {
"start_dt": "",
"end_dt": "",
"power": 0, # 力度
"direction": "up",
"high": 0,
"low": 0,
"mode": "bi"
}
假定最近一段走势为第N段;则 fd1 为第N-4段走势, fd2为第N-3段走势,
fd3为第N-2段走势, fd4为第N-1段走势, fd5为第N段走势
"""
assert
fd1
[
'direction'
]
==
fd3
[
'direction'
]
==
fd5
[
'direction'
]
assert
fd2
[
'direction'
]
==
fd4
[
'direction'
]
direction
=
fd1
[
'direction'
]
zs_g
=
min
(
fd2
[
'high'
],
fd3
[
'high'
],
fd4
[
'high'
])
zs_d
=
max
(
fd2
[
'low'
],
fd3
[
'low'
],
fd4
[
'low'
])
jing
=
{
"jing"
:
"没有出井"
,
"notes"
:
""
}
# 1的力度最小,5的力度次之,3的力度最大,此类不算井
if
fd1
[
'power'
]
<
fd5
[
'power'
]
<
fd3
[
'power'
]:
jing
[
'notes'
]
=
"1的力度最小,5的力度次之,3的力度最大,此类不算井"
return
jing
if
zs_d
<
zs_g
:
# 234有中枢的情况
if
direction
==
'up'
and
fd5
[
"high"
]
>
min
(
fd3
[
'high'
],
fd1
[
'high'
]):
# 大井对应的形式是:12345向上,5最高3次之1最低,力度上1大于3,3大于5
if
fd5
[
"high"
]
>
fd3
[
'high'
]
>
fd1
[
'high'
]
and
fd5
[
'power'
]
<
fd3
[
'power'
]
<
fd1
[
'power'
]:
jing
=
{
"jing"
:
"向上大井"
,
"notes"
:
"12345向上,5最高3次之1最低,力度上1大于3,3大于5"
}
# 第一种小井:12345向上,3最高5次之1最低,力度上5的力度比1小
if
fd1
[
'high'
]
<
fd5
[
'high'
]
<
fd3
[
'high'
]
and
fd5
[
'power'
]
<
fd1
[
'power'
]:
jing
=
{
"jing"
:
"向上小井"
,
"notes"
:
"12345向上,3最高5次之1最低,力度上5的力度比1小"
}
# 第二种小井:12345向上,5最高3次之1最低,力度上1大于5,5大于3
if
fd5
[
"high"
]
>
fd3
[
'high'
]
>
fd1
[
'high'
]
and
fd1
[
'power'
]
>
fd5
[
'power'
]
>
fd3
[
'power'
]:
jing
=
{
"jing"
:
"向上小井"
,
"notes"
:
"12345向上,5最高3次之1最低,力度上1大于5,5大于3"
}
if
direction
==
'down'
and
fd5
[
"low"
]
<
max
(
fd3
[
'low'
],
fd1
[
'low'
]):
# 大井对应的形式是:12345向下,5最低3次之1最高,力度上1大于3,3大于5
if
fd5
[
'low'
]
<
fd3
[
'low'
]
<
fd1
[
'low'
]
and
fd5
[
'power'
]
<
fd3
[
'power'
]
<
fd1
[
'power'
]:
jing
=
{
"jing"
:
"向下大井"
,
"notes"
:
"12345向下,5最低3次之1最高,力度上1大于3,3大于5"
}
# 第一种小井:12345向下,3最低5次之1最高,力度上5的力度比1小
if
fd1
[
"low"
]
>
fd5
[
'low'
]
>
fd3
[
'low'
]
and
fd5
[
'power'
]
<
fd1
[
'power'
]:
jing
=
{
"jing"
:
"向下小井"
,
"notes"
:
"12345向下,3最低5次之1最高,力度上5的力度比1小"
}
# 第二种小井:12345向下,5最低3次之1最高,力度上1大于5,5大于3
if
fd5
[
'low'
]
<
fd3
[
'low'
]
<
fd1
[
'low'
]
and
fd1
[
'power'
]
>
fd5
[
'power'
]
>
fd3
[
'power'
]:
jing
=
{
"jing"
:
"向下小井"
,
"notes"
:
"12345向下,5最低3次之1最高,力度上1大于5,5大于3"
}
else
:
# 第三种小井:12345类趋势,力度依次降低,可以看成小井
if
fd1
[
'power'
]
>
fd3
[
'power'
]
>
fd5
[
'power'
]:
if
direction
==
'up'
and
fd5
[
"high"
]
>
fd3
[
'high'
]
>
fd1
[
'high'
]:
jing
=
{
"jing"
:
"向上小井"
,
"notes"
:
"12345类上涨趋势,力度依次降低"
}
if
direction
==
'down'
and
fd5
[
"low"
]
<
fd3
[
'low'
]
<
fd1
[
'low'
]:
jing
=
{
"jing"
:
"向下小井"
,
"notes"
:
"12345类下跌趋势,力度依次降低"
}
return
jing
def
check_bei_chi
(
fd1
,
fd2
,
fd3
,
fd4
,
fd5
):
"""检查最近5个分段走势是否有背驰
fd 为 dict 对象,表示一段走势,可以是笔、线段,样例如下:
fd = {
"start_dt": "",
"end_dt": "",
"power": 0, # 力度
"direction": "up",
"high": 0,
"low": 0,
"mode": "bi"
}
"""
assert
fd1
[
'direction'
]
==
fd3
[
'direction'
]
==
fd5
[
'direction'
]
assert
fd2
[
'direction'
]
==
fd4
[
'direction'
]
direction
=
fd1
[
'direction'
]
zs_g
=
min
(
fd2
[
'high'
],
fd3
[
'high'
],
fd4
[
'high'
])
zs_d
=
max
(
fd2
[
'low'
],
fd3
[
'low'
],
fd4
[
'low'
])
bc
=
{
"bc"
:
"没有背驰"
,
"notes"
:
""
}
if
max
(
fd5
[
'power'
],
fd3
[
'power'
],
fd1
[
'power'
])
==
fd5
[
'power'
]:
bc
=
{
"bc"
:
"没有背驰"
,
"notes"
:
"5的力度最大,没有背驰"
}
return
bc
if
zs_d
<
zs_g
:
if
fd5
[
'power'
]
<
fd1
[
'power'
]:
if
direction
==
'up'
and
fd5
[
"high"
]
>
min
(
fd3
[
'high'
],
fd1
[
'high'
]):
bc
=
{
"bc"
:
"向上趋势背驰"
,
"notes"
:
"12345向上,234构成中枢,5最高,力度上1大于5"
}
if
direction
==
'down'
and
fd5
[
"low"
]
<
max
(
fd3
[
'low'
],
fd1
[
'low'
]):
bc
=
{
"bc"
:
"向下趋势背驰"
,
"notes"
:
"12345向下,234构成中枢,5最低,力度上1大于5"
}
else
:
if
fd5
[
'power'
]
<
fd3
[
'power'
]:
if
direction
==
'up'
and
fd5
[
"high"
]
>
fd3
[
'high'
]:
bc
=
{
"bc"
:
"向上盘整背驰"
,
"notes"
:
"12345向上,234不构成中枢,5最高,力度上1大于5"
}
if
direction
==
'down'
and
fd5
[
"low"
]
<
fd3
[
'low'
]:
bc
=
{
"bc"
:
"向下盘整背驰"
,
"notes"
:
"12345向下,234不构成中枢,5最低,力度上1大于5"
}
return
bc
def
check_third_bs
(
fd1
,
fd2
,
fd3
,
fd4
,
fd5
):
"""输入5段走势,判断是否存在第三类买卖点"""
zs_d
=
max
(
fd1
[
'low'
],
fd2
[
'low'
],
fd3
[
'low'
])
zs_g
=
min
(
fd1
[
'high'
],
fd2
[
'high'
],
fd3
[
'high'
])
third_bs
=
{
"third_bs"
:
"没有第三类买卖点"
,
"notes"
:
""
}
if
max
(
fd1
[
'power'
],
fd2
[
'power'
],
fd3
[
'power'
],
fd4
[
'power'
],
fd5
[
'power'
])
!=
fd4
[
'power'
]:
third_bs
=
{
"third_bs"
:
"没有第三类买卖点"
,
"notes"
:
"第四段不是力度最大的段"
}
return
third_bs
if
zs_g
<
zs_d
:
third_bs
=
{
"third_bs"
:
"没有第三类买卖点"
,
"notes"
:
"前三段不构成中枢,无第三类买卖点"
}
else
:
if
fd4
[
'low'
]
<
zs_d
and
fd5
[
'high'
]
<
zs_d
:
third_bs
=
{
"third_bs"
:
"三卖"
,
"notes"
:
"前三段构成中枢,第四段向下离开,第五段不回中枢"
}
if
fd4
[
'high'
]
>
zs_g
and
fd5
[
'low'
]
>
zs_g
:
third_bs
=
{
"third_bs"
:
"三买"
,
"notes"
:
"前三段构成中枢,第四段向上离开,第五段不回中枢"
}
return
third_bs
def
get_fx_signals
(
ka
):
"""计算分型特征"""
s
=
{
...
...
czsc/utils.py
浏览文件 @
d0a388a4
...
...
@@ -4,12 +4,10 @@ import pandas as pd
import
mplfinance
as
mpf
import
matplotlib
as
mpl
import
matplotlib.pyplot
as
plt
from
pyecharts
import
options
as
opts
from
pyecharts.charts
import
Kline
,
Line
,
Bar
,
Scatter
,
Grid
from
pyecharts.commons.utils
import
JsCode
from
.plot
import
kline_pro
def
plot_ka
(
ka
,
file_image
,
mav
=
(
5
,
20
,
120
,
250
),
max_k_count
=
1000
,
dpi
=
50
):
def
ka_to_image
(
ka
,
file_image
,
mav
=
(
5
,
20
,
120
,
250
),
max_k_count
=
1000
,
dpi
=
50
):
"""绘制 ka,保存到 file_image"""
df
=
ka
.
to_df
(
use_macd
=
True
,
ma_params
=
(
5
,
20
,),
max_count
=
max_k_count
)
df
.
rename
({
"open"
:
"Open"
,
"close"
:
"Close"
,
"high"
:
"High"
,
...
...
@@ -57,7 +55,9 @@ def plot_ka(ka, file_image, mav=(5, 20, 120, 250), max_k_count=1000, dpi=50):
plt
.
close
()
def
ka_to_echarts
(
ka
,
width
=
"1500px"
,
height
=
'800px'
):
def
ka_to_echarts
(
ka
,
width
:
str
=
"1500px"
,
height
:
str
=
'800px'
):
"""用 pyecharts 绘制分析结果
:param ka: KlineAnalyze
...
...
@@ -65,200 +65,9 @@ def ka_to_echarts(ka, width="1500px", height='800px'):
:param height: str
:return:
"""
# 配置项设置
# ------------------------------------------------------------------------------------------------------------------
bg_color
=
"#1f212d"
# 背景
up_color
=
"#F9293E"
down_color
=
"#00aa3b"
init_opts
=
opts
.
InitOpts
(
bg_color
=
bg_color
,
width
=
width
,
height
=
height
,
animation_opts
=
opts
.
AnimationOpts
(
False
))
title_opts
=
opts
.
TitleOpts
(
title
=
"{} - {}"
.
format
(
ka
.
symbol
,
ka
.
name
),
subtitle
=
"from {} to {}"
.
format
(
ka
.
start_dt
,
ka
.
end_dt
),
pos_top
=
"1%"
,
title_textstyle_opts
=
opts
.
TextStyleOpts
(
color
=
up_color
,
font_size
=
20
),
subtitle_textstyle_opts
=
opts
.
TextStyleOpts
(
color
=
down_color
,
font_size
=
12
))
label_not_show_opts
=
opts
.
LabelOpts
(
is_show
=
False
)
legend_not_show_opts
=
opts
.
LegendOpts
(
is_show
=
False
)
red_item_style
=
opts
.
ItemStyleOpts
(
color
=
up_color
)
green_item_style
=
opts
.
ItemStyleOpts
(
color
=
down_color
)
k_style_opts
=
opts
.
ItemStyleOpts
(
color
=
up_color
,
color0
=
down_color
,
border_color
=
up_color
,
border_color0
=
down_color
,
opacity
=
0.8
)
legend_opts
=
opts
.
LegendOpts
(
is_show
=
True
,
pos_top
=
"1%"
,
pos_left
=
"30%"
,
item_width
=
14
,
item_height
=
8
,
textstyle_opts
=
opts
.
TextStyleOpts
(
font_size
=
12
,
color
=
"#0e99e2"
))
brush_opts
=
opts
.
BrushOpts
(
tool_box
=
[
"rect"
,
"polygon"
,
"keep"
,
"clear"
],
x_axis_index
=
"all"
,
brush_link
=
"all"
,
out_of_brush
=
{
"colorAlpha"
:
0.1
},
brush_type
=
"lineX"
)
axis_pointer_opts
=
opts
.
AxisPointerOpts
(
is_show
=
True
,
link
=
[{
"xAxisIndex"
:
"all"
}])
dz_inside
=
opts
.
DataZoomOpts
(
False
,
"inside"
,
xaxis_index
=
[
0
,
1
,
2
],
range_start
=
80
,
range_end
=
100
)
dz_slider
=
opts
.
DataZoomOpts
(
True
,
"slider"
,
xaxis_index
=
[
0
,
1
,
2
],
pos_top
=
"96%"
,
pos_bottom
=
"0.5%"
,
range_start
=
80
,
range_end
=
100
)
yaxis_opts
=
opts
.
AxisOpts
(
is_scale
=
True
,
axislabel_opts
=
opts
.
LabelOpts
(
color
=
"#c7c7c7"
,
font_size
=
8
,
position
=
"inside"
))
grid0_xaxis_opts
=
opts
.
AxisOpts
(
type_
=
"category"
,
grid_index
=
0
,
axislabel_opts
=
label_not_show_opts
,
split_number
=
20
,
min_
=
"dataMin"
,
max_
=
"dataMax"
,
is_scale
=
True
,
boundary_gap
=
False
,
axisline_opts
=
opts
.
AxisLineOpts
(
is_on_zero
=
False
))
tool_tip_opts
=
opts
.
TooltipOpts
(
trigger
=
"axis"
,
axis_pointer_type
=
"cross"
,
background_color
=
"rgba(245, 245, 245, 0.8)"
,
border_width
=
1
,
border_color
=
"#ccc"
,
position
=
JsCode
(
"""
function (pos, params, el, elRect, size) {
var obj = {top: 10};
obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 30;
return obj;
}
"""
),
textstyle_opts
=
opts
.
TextStyleOpts
(
color
=
"#000"
),
)
# 数据预处理
# ------------------------------------------------------------------------------------------------------------------
dts
=
[
x
[
'dt'
]
for
x
in
ka
.
kline_raw
]
k_data
=
[[
x
[
'open'
],
x
[
'close'
],
x
[
'low'
],
x
[
'high'
]]
for
x
in
ka
.
kline_raw
]
ma
=
ka
.
ma
vol
=
[]
for
row
in
ka
.
kline_raw
:
item_style
=
red_item_style
if
row
[
'close'
]
>
row
[
'open'
]
else
green_item_style
bar
=
opts
.
BarItem
(
value
=
row
[
'vol'
],
itemstyle_opts
=
item_style
,
label_opts
=
label_not_show_opts
)
vol
.
append
(
bar
)
macd
=
[]
for
row
in
ka
.
macd
:
item_style
=
red_item_style
if
row
[
'macd'
]
>
0
else
green_item_style
bar
=
opts
.
BarItem
(
value
=
round
(
row
[
'macd'
],
4
),
itemstyle_opts
=
item_style
,
label_opts
=
label_not_show_opts
)
macd
.
append
(
bar
)
diff
=
[
round
(
x
[
'diff'
],
4
)
for
x
in
ka
.
macd
]
dea
=
[
round
(
x
[
'dea'
],
4
)
for
x
in
ka
.
macd
]
# K 线主图
# ------------------------------------------------------------------------------------------------------------------
chart_k
=
Kline
()
chart_k
.
add_xaxis
(
xaxis_data
=
dts
)
chart_k
.
add_yaxis
(
series_name
=
"Kline"
,
y_axis
=
k_data
,
itemstyle_opts
=
k_style_opts
)
chart_k
.
set_global_opts
(
legend_opts
=
legend_opts
,
datazoom_opts
=
[
dz_inside
,
dz_slider
],
yaxis_opts
=
yaxis_opts
,
tooltip_opts
=
tool_tip_opts
,
axispointer_opts
=
axis_pointer_opts
,
brush_opts
=
brush_opts
,
title_opts
=
title_opts
,
xaxis_opts
=
grid0_xaxis_opts
)
# 均线图
# ------------------------------------------------------------------------------------------------------------------
chart_ma
=
Line
()
chart_ma
.
add_xaxis
(
xaxis_data
=
dts
)
ma_keys
=
[
x
for
x
in
ma
[
0
].
keys
()
if
"ma"
in
x
]
for
i
,
k
in
enumerate
(
ma_keys
):
y_data
=
[
x
[
k
]
for
x
in
ma
]
chart_ma
.
add_yaxis
(
series_name
=
k
.
upper
(),
y_axis
=
y_data
,
is_smooth
=
True
,
is_selected
=
False
,
symbol_size
=
0
,
label_opts
=
label_not_show_opts
,
linestyle_opts
=
opts
.
LineStyleOpts
(
opacity
=
0.8
,
width
=
1.0
))
chart_ma
.
set_global_opts
(
xaxis_opts
=
grid0_xaxis_opts
,
legend_opts
=
legend_not_show_opts
)
chart_k
=
chart_k
.
overlap
(
chart_ma
)
# 缠论结果
# ------------------------------------------------------------------------------------------------------------------
fx_dts
=
[
x
[
'dt'
]
for
x
in
ka
.
fx_list
]
fx_val
=
[
x
[
'fx'
]
for
x
in
ka
.
fx_list
]
chart_fx
=
Scatter
()
chart_fx
.
add_xaxis
(
fx_dts
)
chart_fx
.
add_yaxis
(
series_name
=
"FX"
,
y_axis
=
fx_val
,
is_selected
=
False
,
symbol
=
"circle"
,
symbol_size
=
6
,
label_opts
=
label_not_show_opts
,
itemstyle_opts
=
opts
.
ItemStyleOpts
(
color
=
"rgba(152, 147, 193, 1.0)"
,))
chart_fx
.
set_global_opts
(
xaxis_opts
=
grid0_xaxis_opts
,
legend_opts
=
legend_not_show_opts
)
chart_k
=
chart_k
.
overlap
(
chart_fx
)
bi_dts
=
[
x
[
'dt'
]
for
x
in
ka
.
bi_list
]
bi_val
=
[
x
[
'bi'
]
for
x
in
ka
.
bi_list
]
chart_bi
=
Scatter
()
chart_bi
.
add_xaxis
(
bi_dts
)
chart_bi
.
add_yaxis
(
series_name
=
"BI"
,
y_axis
=
bi_val
,
is_selected
=
True
,
symbol
=
"diamond"
,
symbol_size
=
10
,
label_opts
=
label_not_show_opts
,
itemstyle_opts
=
opts
.
ItemStyleOpts
(
color
=
"rgba(184, 117, 225, 1.0)"
,))
chart_bi
.
set_global_opts
(
xaxis_opts
=
grid0_xaxis_opts
,
legend_opts
=
legend_not_show_opts
)
chart_k
=
chart_k
.
overlap
(
chart_bi
)
xd_dts
=
[
x
[
'dt'
]
for
x
in
ka
.
xd_list
]
xd_val
=
[
x
[
'xd'
]
for
x
in
ka
.
xd_list
]
chart_xd
=
Scatter
()
chart_xd
.
add_xaxis
(
xd_dts
)
chart_xd
.
add_yaxis
(
series_name
=
"XD"
,
y_axis
=
xd_val
,
is_selected
=
True
,
symbol
=
"triangle"
,
symbol_size
=
10
,
itemstyle_opts
=
opts
.
ItemStyleOpts
(
color
=
"rgba(37, 141, 54, 1.0)"
,))
chart_xd
.
set_global_opts
(
xaxis_opts
=
grid0_xaxis_opts
,
legend_opts
=
legend_not_show_opts
)
chart_k
=
chart_k
.
overlap
(
chart_xd
)
# 成交量图
# ------------------------------------------------------------------------------------------------------------------
chart_vol
=
Bar
()
chart_vol
.
add_xaxis
(
dts
)
chart_vol
.
add_yaxis
(
series_name
=
"Volume"
,
y_axis
=
vol
,
bar_width
=
'60%'
)
chart_vol
.
set_global_opts
(
xaxis_opts
=
opts
.
AxisOpts
(
type_
=
"category"
,
grid_index
=
1
,
axislabel_opts
=
opts
.
LabelOpts
(
is_show
=
True
,
font_size
=
8
,
color
=
"#9b9da9"
),
),
yaxis_opts
=
yaxis_opts
,
legend_opts
=
legend_not_show_opts
,
)
# MACD图
# ------------------------------------------------------------------------------------------------------------------
chart_macd
=
Bar
()
chart_macd
.
add_xaxis
(
dts
)
chart_macd
.
add_yaxis
(
series_name
=
"MACD"
,
y_axis
=
macd
,
bar_width
=
'60%'
)
chart_macd
.
set_global_opts
(
xaxis_opts
=
opts
.
AxisOpts
(
type_
=
"category"
,
grid_index
=
2
,
axislabel_opts
=
opts
.
LabelOpts
(
is_show
=
False
),
),
yaxis_opts
=
opts
.
AxisOpts
(
grid_index
=
2
,
split_number
=
4
,
axisline_opts
=
opts
.
AxisLineOpts
(
is_on_zero
=
False
),
axistick_opts
=
opts
.
AxisTickOpts
(
is_show
=
False
),
splitline_opts
=
opts
.
SplitLineOpts
(
is_show
=
False
),
axislabel_opts
=
opts
.
LabelOpts
(
is_show
=
True
,
color
=
"#c7c7c7"
),
),
legend_opts
=
opts
.
LegendOpts
(
is_show
=
False
),
)
line
=
Line
()
line
.
add_xaxis
(
dts
)
line
.
add_yaxis
(
series_name
=
"DIFF"
,
y_axis
=
diff
,
label_opts
=
label_not_show_opts
,
is_symbol_show
=
False
,
linestyle_opts
=
opts
.
LineStyleOpts
(
opacity
=
0.8
,
width
=
1.0
,
color
=
"#da6ee8"
))
line
.
add_yaxis
(
series_name
=
"DEA"
,
y_axis
=
dea
,
label_opts
=
label_not_show_opts
,
is_symbol_show
=
False
,
linestyle_opts
=
opts
.
LineStyleOpts
(
opacity
=
0.8
,
width
=
1.0
,
color
=
"#39afe6"
))
chart_macd
=
chart_macd
.
overlap
(
line
)
grid0_opts
=
opts
.
GridOpts
(
pos_left
=
"0%"
,
pos_right
=
"1%"
,
pos_top
=
"12%"
,
height
=
"58%"
)
grid1_opts
=
opts
.
GridOpts
(
pos_left
=
"0%"
,
pos_right
=
"1%"
,
pos_top
=
"74%"
,
height
=
"8%"
)
grid2_opts
=
opts
.
GridOpts
(
pos_left
=
"0%"
,
pos_right
=
"1%"
,
pos_top
=
"86%"
,
height
=
"10%"
)
grid_chart
=
Grid
(
init_opts
)
grid_chart
.
add
(
chart_k
,
grid_opts
=
grid0_opts
)
grid_chart
.
add
(
chart_vol
,
grid_opts
=
grid1_opts
)
grid_chart
.
add
(
chart_macd
,
grid_opts
=
grid2_opts
)
return
grid_chart
chart
=
kline_pro
(
ka
.
kline_raw
,
ma
=
ka
.
ma
,
macd
=
ka
.
macd
,
fx
=
ka
.
fx_list
,
bi
=
ka
.
bi_list
,
xd
=
ka
.
xd_list
,
width
=
width
,
height
=
height
)
return
chart
class
KlineGenerator
:
"""K线生成器,仿实盘"""
...
...
test/test_signals.py
浏览文件 @
d0a388a4
...
...
@@ -4,7 +4,7 @@ import sys
sys
.
path
.
insert
(
0
,
'.'
)
sys
.
path
.
insert
(
0
,
'..'
)
from
czsc.
signals
import
check_jing
,
check_bei_chi
,
check_third_bs
from
czsc.
analyze
import
check_jing
,
check_bei_chi
,
check_third_bs
def
test_check_jing_up
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录