Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zengbin93
czsc
提交
d405414c
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 搜索 >>
提交
d405414c
编写于
9月 12, 2020
作者:
Z
zengbin93
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
0.5.4 新增获取分段方法
上级
7ff8339f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
106 addition
and
7 deletion
+106
-7
czsc/analyze.py
czsc/analyze.py
+105
-4
czsc/signals.py
czsc/signals.py
+1
-3
未找到文件。
czsc/analyze.py
浏览文件 @
d405414c
...
...
@@ -12,7 +12,6 @@ except ImportError:
warnings
.
warn
(
ta_lib_hint
)
import
pandas
as
pd
import
numpy
as
np
from
datetime
import
datetime
from
czsc.utils
import
plot_ka
def
find_zs
(
points
):
...
...
@@ -809,7 +808,7 @@ class KlineAnalyze:
return
bc
def
get_sub_section
(
self
,
start_dt
:
datetime
,
end_dt
:
datetime
,
mode
=
"bi"
,
is_last
=
True
):
def
get_sub_section
(
self
,
start_dt
,
end_dt
,
mode
=
"bi"
,
is_last
=
True
):
"""获取子区间
:param start_dt: datetime
...
...
@@ -847,7 +846,7 @@ class KlineAnalyze:
return
[
x
for
x
in
points
if
end_dt
>=
x
[
'dt'
]
>=
start_dt
]
def
calculate_macd_power
(
self
,
start_dt
:
datetime
,
end_dt
:
datetime
,
mode
=
'bi'
,
direction
=
"up"
):
def
calculate_macd_power
(
self
,
start_dt
,
end_dt
,
mode
=
'bi'
,
direction
=
"up"
):
"""用 MACD 计算走势段(start_dt ~ end_dt)的力度
:param start_dt: datetime
...
...
@@ -876,7 +875,7 @@ class KlineAnalyze:
raise
ValueError
return
power
def
calculate_vol_power
(
self
,
start_dt
:
datetime
,
end_dt
:
datetime
):
def
calculate_vol_power
(
self
,
start_dt
,
end_dt
):
"""用 VOL 计算走势段(start_dt ~ end_dt)的力度
:param start_dt: datetime
...
...
@@ -890,3 +889,105 @@ class KlineAnalyze:
power
=
sum
([
x
[
'vol'
]
for
x
in
fd_vol
])
return
int
(
power
)
def
get_latest_fd
(
self
,
n
=
6
,
mode
=
"bi"
):
"""获取最近的走势分段
fd 为 dict 对象,表示一段走势,可以是笔、线段,样例如下:
fd = {
"start_dt": "",
"end_dt": "",
"power": 0, # 力度
"direction": "up",
"high": 0,
"low": 0,
"mode": "bi"
}
:param n:
:param mode:
:return: list of dict
"""
if
mode
==
'bi'
:
points
=
self
.
bi_list
[
-
(
n
+
1
):]
elif
mode
==
'xd'
:
points
=
self
.
xd_list
[
-
(
n
+
1
):]
else
:
raise
ValueError
res
=
[]
for
i
in
range
(
len
(
points
)
-
1
):
p1
=
points
[
i
]
p2
=
points
[
i
+
1
]
direction
=
"up"
if
p1
[
mode
]
<
p2
[
mode
]
else
"down"
power
=
self
.
calculate_macd_power
(
start_dt
=
p1
[
'dt'
],
end_dt
=
p2
[
'dt'
],
mode
=
mode
,
direction
=
direction
)
res
.
append
({
"start_dt"
:
p1
[
'dt'
],
"end_dt"
:
p2
[
'dt'
],
"power"
:
power
,
"direction"
:
direction
,
"high"
:
max
(
p1
[
mode
],
p2
[
mode
]),
"low"
:
min
(
p1
[
mode
],
p2
[
mode
]),
"mode"
:
mode
})
return
res
def
get_last_fd
(
self
,
mode
=
'bi'
):
"""获取最后一个分段走势
:param mode: str
可选值 ['bi', 'xd'],默认值 'bi'
:return:
"""
if
mode
==
'bi'
:
p1
=
self
.
bi_list
[
-
1
]
points
=
[
x
for
x
in
self
.
fx_list
[
-
60
:]
if
x
[
'dt'
]
>=
p1
[
'dt'
]]
if
len
(
points
)
<
2
:
return
None
if
p1
[
'fx_mark'
]
==
'd'
:
direction
=
"up"
max_fx
=
max
([
x
[
'fx'
]
for
x
in
points
if
x
[
'fx_mark'
]
==
'g'
])
p2
=
[
x
for
x
in
points
if
x
[
'fx'
]
==
max_fx
][
0
]
elif
p1
[
'fx_mark'
]
==
'g'
:
direction
=
"down"
min_fx
=
min
([
x
[
'fx'
]
for
x
in
points
if
x
[
'fx_mark'
]
==
'd'
])
p2
=
[
x
for
x
in
points
if
x
[
'fx'
]
==
min_fx
][
0
]
else
:
raise
ValueError
p2
=
dict
(
p2
)
p2
[
'bi'
]
=
p2
.
pop
(
'fx'
)
elif
mode
==
'xd'
:
p1
=
self
.
xd_list
[
-
1
]
points
=
[
x
for
x
in
self
.
bi_list
[
-
60
:]
if
x
[
'dt'
]
>=
p1
[
'dt'
]]
if
len
(
points
)
<
4
:
return
None
if
p1
[
'fx_mark'
]
==
'd'
:
direction
=
"up"
max_fx
=
max
([
x
[
'bi'
]
for
x
in
points
if
x
[
'fx_mark'
]
==
'g'
])
p2
=
[
x
for
x
in
points
if
x
[
'bi'
]
==
max_fx
][
0
]
elif
p1
[
'fx_mark'
]
==
'g'
:
direction
=
"down"
min_fx
=
min
([
x
[
'bi'
]
for
x
in
points
if
x
[
'fx_mark'
]
==
'd'
])
p2
=
[
x
for
x
in
points
if
x
[
'bi'
]
==
min_fx
][
0
]
else
:
raise
ValueError
p2
=
dict
(
p2
)
p2
[
'xd'
]
=
p2
.
pop
(
'bi'
)
else
:
raise
ValueError
power
=
self
.
calculate_macd_power
(
start_dt
=
p1
[
'dt'
],
end_dt
=
p2
[
'dt'
],
mode
=
mode
,
direction
=
direction
)
return
{
"start_dt"
:
p1
[
'dt'
],
"end_dt"
:
p2
[
'dt'
],
"power"
:
power
,
"direction"
:
direction
,
"high"
:
max
(
p1
[
mode
],
p2
[
mode
]),
"low"
:
min
(
p1
[
mode
],
p2
[
mode
]),
"mode"
:
mode
}
czsc/signals.py
浏览文件 @
d405414c
...
...
@@ -357,9 +357,7 @@ class Signals:
K线数据
"""
self
.
klines
=
klines
self
.
kas
=
{
k
:
KlineAnalyze
(
self
.
klines
[
k
],
name
=
k
,
min_bi_k
=
5
,
ma_params
=
(
5
,
20
,
120
),
max_raw_len
=
5000
,
verbose
=
False
)
self
.
kas
=
{
k
:
KlineAnalyze
(
self
.
klines
[
k
],
name
=
k
,
ma_params
=
(
5
,
20
,
120
),
max_xd_len
=
20
,
verbose
=
False
)
for
k
in
self
.
klines
.
keys
()}
self
.
symbol
=
self
.
kas
[
"1分钟"
].
symbol
self
.
end_dt
=
self
.
kas
[
"1分钟"
].
end_dt
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录