PTrade获取股票信息
更加详细的调用方法,后续会慢慢整理。
也可找寻博主历史文章,搜索关键词使用方案,比如本文涉及函数get_stock_exrights!
感谢关注,咨询免费开通量化回测与获取实盘权限,欢迎和博主联系!
get_stock_exrights - 获取股票除权除息信息
get_stock_exrights(stock_code, date=None)
使用场景
该函数在研究、回测、交易模块可用
接口说明
该接口用于获取股票除权除息信息。
注意事项:
无
参数
stock_code; str类型, 股票代码(str);
date: 查询该日期的除权除息信息,默认获取该股票历史上所有除权除息信息,e.g. '20180228'/20180228/datetime.date(2018,2,28)(str/int/datetime.date)
返回
输入日期若没有除权除息信息则返回None,有相关数据则返回pandas.DataFrame类型数据
例如输入get_stock_exrights('600570.SS'),返回
allotted_ps rationed_ps rationed_px bonus_ps exer_forward_a exer_forward_b exer_backward_a exer_backward_b
date
20040604 0.0 0.0 0.0 0.43 0.046077 -1.433 1.000000 0.430
20050601 0.5 0.0 0.0 0.20 0.046077 -1.413 1.500000 0.630
20050809 0.4 0.0 0.0 0.00 0.069115 -1.404 2.100000 0.630
20060601 0.4 0.0 0.0 0.11 0.096762 -1.404 2.940000 0.861
20070423 0.3 0.0 0.0 0.10 0.135466 -1.394 3.822000 1.155
20080528 0.6 0.0 0.0 0.07 0.176106 -1.380 6.115200 1.422
20090423 0.5 0.0 0.0 0.10 0.281770 -1.368 9.172799 2.034
20100510 0.4 0.0 0.0 0.05 0.422654 -1.340 12.841919 2.492
20110517 0.0 0.0 0.0 0.05 0.591716 -1.318 12.841919 3.134
20120618 0.0 0.0 0.0 0.08 0.591716 -1.289 12.841919 4.162
20130514 0.0 0.0 0.0 0.10 0.591716 -1.242 12.841919 5.446
20140523 0.0 0.0 0.0 0.16 0.591716 -1.182 12.841919 7.501
20150529 0.0 0.0 0.0 0.18 0.591716 -1.088 12.841919 9.812
20160530 0.0 0.0 0.0 0.26 0.591716 -0.981 12.841919 13.151
20170510 0.0 0.0 0.0 0.10 0.591716 -0.827 12.841919 14.435
20180524 0.0 0.0 0.0 0.29 0.591716 -0.768 12.841919 18.159
20190515 0.3 0.0 0.0 0.32 0.591716 -0.597 16.694494 22.269
20200605 0.3 0.0 0.0 0.53 0.769231 -0.407 21.702843 31.117
返回结果字段介绍:
- date -- 日期(索引列,类型为int64);
- allotted_ps -- 每股送股(str:numpy.float64);
- rationed_ps -- 每股配股(str:numpy.float64);
- rationed_px -- 配股价(str:numpy.float64);
- bonus_ps -- 每股分红(str:numpy.float64);
- exer_forward_a -- 前复权除权因子A;用于计算前复权价格(前复权价格=A*价格+B)(str:numpy.float64)
- exer_forward_b -- 前复权除权因子B;用于计算前复权价格(前复权价格=A*价格+B)(str:numpy.float64)
- exer_backward_a -- 后复权除权因子A;用于计算后复权价格(后复权价格=A*价格+B)(str:numpy.float64)
- exer_backward_b -- 后复权除权因子B;用于计算后复权价格(后复权价格=A*价格+B)(str:numpy.float64)
示例
def initialize(context):
g.security = '600570.SS'
set_universe(g.security)
def handle_data(context, data):
stock_exrights = get_stock_exrights(g.security)
log.info('the stock exrights info of security %s:\n%s' % (g.security, stock_exrights))