Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zengbin93
czsc
提交
bc5d967e
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,发现更多精彩内容 >>
提交
bc5d967e
编写于
6月 14, 2019
作者:
Z
zengbin93
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add daily_classifier
上级
1d4ee43e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
91 addition
and
0 deletion
+91
-0
chan/a/__init__.py
chan/a/__init__.py
+9
-0
chan/a/daily_classfier.py
chan/a/daily_classfier.py
+82
-0
未找到文件。
chan/a/__init__.py
0 → 100644
浏览文件 @
bc5d967e
# coding: utf-8
"""
缠论中仅适用与 A股 的方法
"""
from
.daily_classfier
import
daily_classifier
chan/a/daily_classfier.py
0 → 100644
浏览文件 @
bc5d967e
# coding: utf-8
from
datetime
import
datetime
,
timedelta
import
tushare
as
ts
# 首次使用,需要设置token
# ts.set_token("******")
def
daily_classifier
(
ts_code
,
trade_date
,
return_central
=
False
):
""" A 股每日走势的分类
使用该方法前,请仔细阅读:http://blog.sina.com.cn/s/blog_486e105c010009uy.html
每个交易日产生 8 根 30 分钟 K 线,分别在前三根和最后三根中计算中枢,其结果分以下情况:
1)没有中枢;
2)仅有一个中枢,或计算得到的两个中枢区间有重叠;
3)有两个中枢,且没有重叠。
example:
>>> kind, central = daily_classifier('600122.SH', "20190613", return_central=True)
>>> print(kind, central)
"""
start_date
=
datetime
.
strptime
(
trade_date
,
'%Y%m%d'
)
end_date
=
start_date
+
timedelta
(
days
=
1
)
end_date
=
end_date
.
date
().
__str__
().
replace
(
"-"
,
""
)
df
=
ts
.
pro_bar
(
ts_code
=
ts_code
,
freq
=
'30min'
,
start_date
=
trade_date
,
end_date
=
end_date
)
df
.
sort_values
(
'trade_time'
,
inplace
=
True
)
data
=
df
[[
'ts_code'
,
'trade_time'
,
'high'
,
'low'
]].
iloc
[
1
:,
:]
data
=
data
.
reset_index
(
drop
=
True
)
assert
len
(
data
)
==
8
,
"每个交易日,A股有且只有8跟30分钟K线"
def
_central
(
tri
):
c_low
=
max
(
tri
[
'low'
])
c_high
=
min
(
tri
[
'high'
])
if
c_low
>=
c_high
:
# None means no central found
central
=
None
else
:
central
=
{
"time_span"
:
"%s - %s"
%
(
tri
.
iloc
[
0
,
1
],
tri
.
iloc
[
2
,
1
]),
"price_span"
:
(
c_low
,
c_high
)
}
return
central
first_central
=
_central
(
data
.
iloc
[:
3
,
:])
last_central
=
_central
(
data
.
iloc
[
-
3
:,
:])
# 没有中枢的情况
if
first_central
is
None
and
last_central
is
None
:
kind
=
"最强单边走势"
# 一个中枢的情况(平衡市)
elif
(
first_central
is
None
and
last_central
)
or
(
first_central
and
last_central
is
None
):
max_p
=
max
(
data
.
iloc
[:
3
,
:][
'close'
])
min_p
=
min
(
data
.
iloc
[:
3
,
:][
'close'
])
# 1、在前三根30分钟K线出现当天高点
if
max
(
data
[
'close'
])
==
max_p
:
kind
=
"弱平衡市"
# 2、在前三根30分钟K线出现当天低点
elif
min
(
data
[
'close'
])
==
min_p
:
kind
=
"强平衡市"
# 3、在前三根30分钟K线不出现当天高低点
else
:
kind
=
"转折平衡市"
# 两个中枢的情况
elif
first_central
and
last_central
:
if
first_central
[
'price_span'
][
0
]
>
last_central
[
'price_span'
][
0
]:
kind
=
"向下两中枢走势"
elif
first_central
[
'price_span'
][
0
]
<
last_central
[
'price_span'
][
0
]:
kind
=
"向上两中枢走势"
else
:
raise
ValueError
(
"两中枢的最低价不可以相等"
)
else
:
raise
ValueError
(
'中枢计算错误'
)
if
return_central
:
return
kind
,
(
first_central
,
last_central
)
else
:
return
kind
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录