Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zengbin93
czsc
提交
d789098e
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,发现更多精彩内容 >>
提交
d789098e
编写于
7月 27, 2020
作者:
Z
zengbin93
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
0.5.1 优化初始化
上级
f0b85abf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
18 deletion
+36
-18
czsc/analyze.py
czsc/analyze.py
+9
-13
test/test_analyze.py
test/test_analyze.py
+27
-5
未找到文件。
czsc/analyze.py
浏览文件 @
d789098e
...
...
@@ -142,10 +142,6 @@ class KlineAnalyze:
self
.
name
=
name
self
.
verbose
=
verbose
self
.
min_bi_k
=
min_bi_k
self
.
symbol
=
None
self
.
latest_price
=
None
self
.
start_dt
=
None
self
.
end_dt
=
None
self
.
kline_raw
=
[]
# 原始K线序列
self
.
kline_new
=
[]
# 去除包含关系的K线序列
...
...
@@ -170,6 +166,12 @@ class KlineAnalyze:
self
.
kline_raw
=
[{
k
:
v
for
k
,
v
in
zip
(
columns
,
row
)}
for
row
in
kline
.
values
]
else
:
self
.
kline_raw
=
kline
self
.
symbol
=
self
.
kline_raw
[
0
][
'symbol'
]
self
.
start_dt
=
self
.
kline_raw
[
0
][
'dt'
]
self
.
end_dt
=
self
.
kline_raw
[
-
1
][
'dt'
]
self
.
latest_price
=
self
.
kline_raw
[
-
1
][
'close'
]
self
.
_update_kline_new
()
self
.
_update_fx_list
()
self
.
_update_bi_list
()
...
...
@@ -185,8 +187,7 @@ class KlineAnalyze:
'close': 3210.1,
'high': 3373.53,
'low': 3209.76,
'vol': 486366915.0,
'is_end': True}
'vol': 486366915.0}
无包含关系K线对象样例:
{'symbol': '000001.SH',
...
...
@@ -195,9 +196,7 @@ class KlineAnalyze:
'close': 3210.1,
'high': 3373.53,
'low': 3209.76,
'vol': 486366915.0,
'is_end': True,
'direction': 'down'}
'vol': 486366915.0}
"""
if
len
(
self
.
kline_new
)
<
4
:
for
x
in
self
.
kline_raw
[:
4
]:
...
...
@@ -501,10 +500,7 @@ class KlineAnalyze:
print
(
f
"输入K线处于未完成状态,更新:replace
{
self
.
kline_raw
[
-
1
]
}
with
{
k
}
"
)
self
.
kline_raw
[
-
1
]
=
k
self
.
symbol
=
k
[
'symbol'
]
self
.
end_dt
=
k
[
'dt'
]
self
.
latest_price
=
k
[
'close'
]
self
.
start_dt
=
self
.
kline_raw
[
0
][
'dt'
]
self
.
_update_kline_new
()
self
.
_update_fx_list
()
...
...
test/test_analyze.py
浏览文件 @
d789098e
...
...
@@ -2,25 +2,47 @@
import
sys
import
warnings
from
cobra.data.kline
import
get_kline
sys
.
path
.
insert
(
0
,
'.'
)
sys
.
path
.
insert
(
0
,
'..'
)
import
os
import
pandas
as
pd
import
czsc
from
czsc.analyze
import
KlineAnalyze
warnings
.
warn
(
f
"czsc version is
{
czsc
.
__version__
}
"
)
kline
=
get_kline
(
ts_code
=
"000001.SH"
,
end_dt
=
"2020-07-16 15:00:00"
,
freq
=
'D'
,
asset
=
'I'
)
cur_path
=
os
.
path
.
split
(
os
.
path
.
realpath
(
__file__
))[
0
]
file_kline
=
os
.
path
.
join
(
cur_path
,
"data/000001.SH_D.csv"
)
kline
=
pd
.
read_csv
(
file_kline
,
encoding
=
"utf-8"
)
kline
.
loc
[:,
"dt"
]
=
pd
.
to_datetime
(
kline
.
dt
)
kline
.
loc
[:,
"is_end"
]
=
True
# ka = KlineAnalyze(kline, name="日线")
# print(ka)
def
test_kline_analyze
():
ka
=
KlineAnalyze
(
kline
,
name
=
"日线"
)
# 测试绘图
file_img
=
"kline.png"
ka
.
to_image
(
file_img
,
max_k_count
=
5000
)
assert
os
.
path
.
exists
(
file_img
)
os
.
remove
(
file_img
)
file_html
=
"kline.html"
ka
.
to_html
(
file_html
)
assert
os
.
path
.
exists
(
file_html
)
os
.
remove
(
file_html
)
# 测试分型识别结果
assert
ka
.
fx_list
[
-
1
][
'fx_mark'
]
==
'g'
and
ka
.
fx_list
[
-
1
][
'fx'
]
==
3456.97
assert
ka
.
fx_list
[
-
5
][
'fx_mark'
]
==
'g'
and
ka
.
fx_list
[
-
5
][
'fx'
]
==
2983.44
# 测试笔识别结果
assert
ka
.
bi_list
[
-
1
][
'fx_mark'
]
==
'g'
and
ka
.
bi_list
[
-
1
][
'bi'
]
==
3456.97
assert
ka
.
bi_list
[
-
4
][
'fx_mark'
]
==
'd'
and
ka
.
bi_list
[
-
4
][
'bi'
]
==
2646.8
# 测试线段识别结果
assert
ka
.
xd_list
[
-
2
][
'fx_mark'
]
==
'g'
and
ka
.
xd_list
[
-
2
][
'xd'
]
==
3288.45
assert
ka
.
xd_list
[
-
3
][
'fx_mark'
]
==
'd'
and
ka
.
xd_list
[
-
3
][
'xd'
]
==
2440.91
# 测试增量更新
ka_raw_len
=
len
(
ka
.
kline_raw
)
for
x
in
[
2890
,
2910
,
2783
,
3120
]:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录