Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zengbin93
czsc
提交
6e02cd03
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,发现更多精彩内容 >>
提交
6e02cd03
编写于
8月 11, 2019
作者:
Z
zengbin93
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
ecce90af
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
13 deletion
+42
-13
chan/utils.py
chan/utils.py
+16
-12
chan/web/vis_kline.py
chan/web/vis_kline.py
+8
-1
test/test_kline_viewer.py
test/test_kline_viewer.py
+18
-0
未找到文件。
chan/utils.py
浏览文件 @
6e02cd03
...
...
@@ -83,6 +83,8 @@ def find_bi(kline):
1 - 底分型
2 - 无效分型
一个分型能否成为笔的一部分,至少需要看到后面两个分型的情况才能确定。
:param kline: pd.DataFrame
经过预处理,去除了包含关系的 K 线,
columns = ["symbol", "dt", "open", "close", "high", "low", "vol"]
...
...
@@ -94,7 +96,6 @@ def find_bi(kline):
for
i
in
range
(
1
,
len
(
kline
)
-
1
):
data
=
kline
.
iloc
[
i
-
1
:
i
+
2
]
row
=
kline
.
iloc
[
i
]
if
max
(
data
[
'high'
])
==
row
[
'high'
]:
kline
.
loc
[
row
.
name
,
'fx'
]
=
0
elif
min
(
data
[
'low'
])
==
row
[
'low'
]:
...
...
@@ -105,7 +106,8 @@ def find_bi(kline):
# 确定分型的有效性:满足结合律;实现方式:从后往前,不满足结合律就处理成无效分型
last_index
=
None
for
i
in
kline
.
index
[::
-
1
]:
# for i in kline.index[::-1]:
for
i
in
kline
.
index
:
if
kline
.
loc
[
i
,
'fx'
]
not
in
[
0
,
1
]:
continue
...
...
@@ -114,10 +116,12 @@ def find_bi(kline):
last_index
=
i
else
:
curr_index
=
i
if
last_index
-
curr_index
<
3
:
if
curr_index
-
last_index
<
4
:
kline
.
loc
[
last_index
,
'fx'
]
=
2
kline
.
loc
[
curr_index
,
'fx'
]
=
2
last_index
=
None
kline_part
=
kline
.
iloc
[:
i
]
last_index
=
kline_part
[
kline_part
[
'fx'
].
isin
([
0
,
1
])].
iloc
[
-
1
].
name
last_index
=
int
(
last_index
)
else
:
last_index
=
curr_index
...
...
@@ -203,7 +207,7 @@ def ma(kline, params=(5, 10, 20, 60, 120, 250)):
for
p
in
params
:
col
=
"ma"
+
str
(
p
)
kline
[
col
]
=
kline
[
'close'
].
rolling
(
p
).
mean
()
kline
[
col
]
=
kline
[
col
].
apply
(
round
,
args
=
(
4
,))
kline
[
col
]
=
kline
[
col
].
apply
(
round
,
args
=
(
2
,))
return
kline
...
...
@@ -222,9 +226,9 @@ def macd(kline):
kline
[
'dea'
]
=
kline
[
'diff'
].
ewm
(
adjust
=
False
,
alpha
=
2
/
(
m
+
1
),
ignore_na
=
True
).
mean
()
kline
[
'macd'
]
=
2
*
(
kline
[
'diff'
]
-
kline
[
'dea'
])
kline
[
'diff'
]
=
kline
[
'diff'
].
apply
(
round
,
args
=
(
4
,))
kline
[
'dea'
]
=
kline
[
'dea'
].
apply
(
round
,
args
=
(
4
,))
kline
[
'macd'
]
=
kline
[
'macd'
].
apply
(
round
,
args
=
(
4
,))
kline
[
'diff'
]
=
kline
[
'diff'
].
apply
(
round
,
args
=
(
2
,))
kline
[
'dea'
]
=
kline
[
'dea'
].
apply
(
round
,
args
=
(
2
,))
kline
[
'macd'
]
=
kline
[
'macd'
].
apply
(
round
,
args
=
(
2
,))
return
kline
...
...
@@ -241,10 +245,10 @@ def boll(kline):
kline
[
'boll-top'
]
=
kline
[
'boll-mid'
]
+
2
*
kline
[
'boll-tmp2'
]
kline
[
'boll-bottom'
]
=
kline
[
'boll-mid'
]
-
2
*
kline
[
'boll-tmp2'
]
kline
[
'boll-mid'
]
=
kline
[
'boll-mid'
].
apply
(
round
,
args
=
(
4
,))
kline
[
'boll-tmp2'
]
=
kline
[
'boll-tmp2'
].
apply
(
round
,
args
=
(
4
,))
kline
[
'boll-top'
]
=
kline
[
'boll-top'
].
apply
(
round
,
args
=
(
4
,))
kline
[
'boll-bottom'
]
=
kline
[
'boll-bottom'
].
apply
(
round
,
args
=
(
4
,))
kline
[
'boll-mid'
]
=
kline
[
'boll-mid'
].
apply
(
round
,
args
=
(
2
,))
kline
[
'boll-tmp2'
]
=
kline
[
'boll-tmp2'
].
apply
(
round
,
args
=
(
2
,))
kline
[
'boll-top'
]
=
kline
[
'boll-top'
].
apply
(
round
,
args
=
(
2
,))
kline
[
'boll-bottom'
]
=
kline
[
'boll-bottom'
].
apply
(
round
,
args
=
(
2
,))
return
kline
...
...
chan/web/vis_kline.py
浏览文件 @
6e02cd03
...
...
@@ -11,8 +11,10 @@ import webbrowser
from
pyecharts
import
options
as
opts
from
pyecharts.charts
import
Kline
,
Grid
,
Line
,
Bar
,
Scatter
from
pyecharts.globals
import
ThemeType
,
CurrentConfig
from
chan.a
import
get_kline
from
chan.utils
import
preprocess
,
find_bi
,
find_xd
,
cache_path
from
chan.utils
import
cache_path
from
chan.analyze
import
preprocess
,
find_fx
,
find_bi
,
find_xd
CurrentConfig
.
PAGE_TITLE
=
"chan - 缠论分析"
...
...
@@ -34,9 +36,14 @@ def kline_viewer(ts_code, freq, end_date, asset='E', show=True):
>>> kline_viewer(ts_code='002739.SZ', freq='1min', end_date="20190809", asset='E')
"""
kline_raw
=
get_kline
(
ts_code
,
freq
=
freq
,
end_date
=
end_date
,
asset
=
asset
,
indicators
=
(
'ma'
,
'macd'
))
for
col
in
[
'open'
,
'close'
,
'high'
,
'low'
]:
kline_raw
[
col
]
=
kline_raw
[
col
].
apply
(
round
,
args
=
(
2
,))
kline_chan
=
find_xd
(
find_bi
(
preprocess
(
kline_raw
)))
kline_chan
=
kline_chan
[[
'dt'
,
'fx'
,
'bi_mark'
,
'bi'
,
'xd_mark'
]]
kline_raw
=
kline_raw
.
merge
(
kline_chan
,
how
=
'left'
,
on
=
'dt'
)
# kline_raw = kline_raw.merge(kline_chan, how='right', on='dt')
start_dt
=
kline_raw
.
iloc
[
0
][
"dt"
]
end_dt
=
kline_raw
.
iloc
[
-
1
][
"dt"
]
...
...
test/test_kline_viewer.py
0 → 100644
浏览文件 @
6e02cd03
# coding: utf-8
import
sys
sys
.
path
.
insert
(
0
,
".."
)
import
os
from
datetime
import
datetime
import
pandas
as
pd
import
chan
from
tqdm
import
tqdm
shares
=
pd
.
read_excel
(
os
.
path
.
join
(
chan
.
cache_path
,
'shares.xlsx'
),
sheets
=
'pool'
)
today
=
datetime
.
now
().
date
().
__str__
().
replace
(
"-"
,
''
)
chan
.
kline_viewer
(
ts_code
=
'000001.SH'
,
freq
=
'5min'
,
end_date
=
today
,
asset
=
'I'
,
show
=
True
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录