Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zengbin93
czsc
提交
8a7e26d9
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 搜索 >>
提交
8a7e26d9
编写于
7月 31, 2020
作者:
Z
zengbin93
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
0.5.2 修复bug,辅助技术指标计算
上级
b65c87d0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
6 deletion
+22
-6
czsc/analyze.py
czsc/analyze.py
+12
-2
test/test_analyze.py
test/test_analyze.py
+10
-4
未找到文件。
czsc/analyze.py
浏览文件 @
8a7e26d9
...
...
@@ -161,12 +161,15 @@ class KlineAnalyze:
ma_
=
{
'ma%i'
%
p
:
sum
([
x
[
'close'
]
for
x
in
self
.
kline_raw
[
-
p
:]])
/
p
for
p
in
self
.
ma_params
}
ma_
.
update
({
"dt"
:
self
.
kline_raw
[
-
1
][
'dt'
]})
if
self
.
verbose
:
print
(
"ma new: %s"
%
str
(
ma_
))
if
self
.
kline_raw
[
-
2
][
'dt'
]
==
self
.
ma
[
-
1
][
'dt'
]:
self
.
ma
.
append
(
ma_
)
else
:
self
.
ma
[
-
1
]
=
ma_
assert
len
(
self
.
ma
)
==
len
(
self
.
kline_raw
)
assert
self
.
ma
[
-
2
][
'dt'
]
==
self
.
kline_raw
[
-
2
][
'dt'
]
if
not
self
.
macd
:
close_
=
np
.
array
([
x
[
"close"
]
for
x
in
self
.
kline_raw
],
dtype
=
np
.
double
)
...
...
@@ -189,11 +192,16 @@ class KlineAnalyze:
"dea"
:
m2
[
-
1
],
"macd"
:
m3
[
-
1
]
}
if
self
.
kline_raw
[
-
2
][
'dt'
]
==
self
.
ma
[
-
1
][
'dt'
]:
if
self
.
verbose
:
print
(
"macd new: %s"
%
str
(
macd_
))
if
self
.
kline_raw
[
-
2
][
'dt'
]
==
self
.
macd
[
-
1
][
'dt'
]:
self
.
macd
.
append
(
macd_
)
else
:
self
.
macd
[
-
1
]
=
macd_
assert
self
.
macd
[
-
2
][
'dt'
]
==
self
.
kline_raw
[
-
2
][
'dt'
]
def
_update_kline_new
(
self
):
"""更新去除包含关系的K线序列
...
...
@@ -534,6 +542,8 @@ class KlineAnalyze:
# 根据最大原始K线序列长度限制分析结果长度
if
len
(
self
.
kline_raw
)
>
self
.
max_raw_len
:
self
.
kline_raw
=
self
.
kline_raw
[
-
self
.
max_raw_len
:]
self
.
ma
=
self
.
ma
[
-
self
.
max_raw_len
:]
self
.
macd
=
self
.
macd
[
-
self
.
max_raw_len
:]
self
.
kline_new
=
self
.
kline_new
[
-
self
.
max_raw_len
:]
self
.
fx_list
=
self
.
fx_list
[
-
(
self
.
max_raw_len
//
2
):]
self
.
bi_list
=
self
.
bi_list
[
-
(
self
.
max_raw_len
//
4
):]
...
...
test/test_analyze.py
浏览文件 @
8a7e26d9
...
...
@@ -13,13 +13,19 @@ from czsc.analyze import KlineAnalyze, find_zs
warnings
.
warn
(
f
"czsc version is
{
czsc
.
__version__
}
"
)
#
cur_path = os.path.split(os.path.realpath(__file__))[0]
cur_path
=
"./test"
cur_path
=
os
.
path
.
split
(
os
.
path
.
realpath
(
__file__
))[
0
]
#
cur_path = "./test"
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
)
ka
=
KlineAnalyze
(
kline
,
name
=
"日线"
,
max_raw_len
=
2000
)
kline1
=
kline
.
iloc
[:
2000
]
kline2
=
kline
.
iloc
[
2000
:]
ka
=
KlineAnalyze
(
kline1
,
name
=
"日线"
,
max_raw_len
=
2000
,
verbose
=
True
)
def
test_update
():
for
_
,
row
in
kline2
.
iterrows
():
ka
.
update
(
row
.
to_dict
())
assert
ka
.
kline_raw
[
-
1
][
'dt'
]
==
row
[
'dt'
]
def
test_update_ta
():
ma_x1
=
dict
(
ka
.
ma
[
-
1
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录