Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zengbin93
czsc
提交
ad2319dd
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 搜索 >>
提交
ad2319dd
编写于
8月 03, 2019
作者:
Z
zengbin93
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add indicators
上级
40c24257
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
25 addition
and
5 deletion
+25
-5
chan/a/utils.py
chan/a/utils.py
+25
-5
未找到文件。
chan/a/utils.py
浏览文件 @
ad2319dd
...
...
@@ -2,8 +2,22 @@
import
tushare
as
ts
from
..utils
import
ma
,
macd
,
boll
def
get_kline
(
ts_code
,
start_date
,
end_date
,
freq
=
'30min'
,
asset
=
'E'
):
def
_cal_indicators
(
kline
,
indicators
):
if
"ma"
in
indicators
:
kline
=
ma
(
kline
)
if
"macd"
in
indicators
:
kline
=
macd
(
kline
)
if
"boll"
in
indicators
:
kline
=
boll
(
kline
)
return
kline
def
get_kline
(
ts_code
,
start_date
,
end_date
,
freq
=
'30min'
,
asset
=
'E'
,
indicators
=
(
"ma"
,
"macd"
)):
"""获取指定级别的前复权K线
:param ts_code: str
...
...
@@ -14,6 +28,8 @@ def get_kline(ts_code, start_date, end_date, freq='30min', asset='E'):
日期,如 20190601
:param end_date: str
日期,如 20190610
:param indicators: tuple
可选值 ma macd boll
:param asset: str
交易资产类型,可选值 E股票 I沪深指数 C数字货币 FT期货 FD基金 O期权 CB可转债(v1.2.39),默认E
:return: pd.DataFrame
...
...
@@ -41,17 +57,19 @@ def get_kline(ts_code, start_date, end_date, freq='30min', asset='E'):
# df['vr'] = 0
# for i in range(5, len(df)):
# df.loc[i, 'vr'] = round(df.loc[i, 'vol'] / df.loc[i-5:i-1, 'vol'].mean(), 4)
return
df
[[
'symbol'
,
'dt'
,
'open'
,
'close'
,
'high'
,
'low'
,
'vol'
]]
kline
=
df
[[
'symbol'
,
'dt'
,
'open'
,
'close'
,
'high'
,
'low'
,
'vol'
]]
return
_cal_indicators
(
kline
,
indicators
)
def
get_realtime_kline
(
ts_code
,
freq
=
"5min"
):
def
get_realtime_kline
(
ts_code
,
freq
=
"5min"
,
indicators
=
(
"ma"
,
"macd"
)
):
"""实时获取分钟K线(仅适用于A股股票)
:param ts_code: str
tushare 股票代码,如 600122.SH
:param freq: str
K线周期,分钟级别,可选值 5min 15min 30min 60min
:param indicators: tuple
可选值 ma macd boll
:return: pd.DataFrame
columns = ["symbol", "dt", "open", "close", "high", "low", "vol"]
...
...
@@ -64,6 +82,8 @@ def get_realtime_kline(ts_code, freq="5min"):
df
.
sort_values
(
'dt'
,
inplace
=
True
)
df
.
reset_index
(
drop
=
True
,
inplace
=
True
)
return
df
[[
"symbol"
,
"dt"
,
"open"
,
"close"
,
"high"
,
"low"
,
"vol"
]]
kline
=
df
[[
'symbol'
,
'dt'
,
'open'
,
'close'
,
'high'
,
'low'
,
'vol'
]]
return
_cal_indicators
(
kline
,
indicators
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录