QMT · 内置 Python行情函数
ContextInfo.get_financial_data
获取财务数据,方法1
财务数据接口有两种用法,入参和返回值不同,具体如下
用法1
原型
ContextInfo.get_financial_data(fieldList, stockList, startDate, enDate, report_type = 'announce_time')
释义
获取财务数据,方法1
参数
| 字段名 | 类型 | 释义与用例 |
|---|---|---|
fieldList |
List(必须) |
财报字段列表:['ASHAREBALANCESHEET.fix_assets', '利润表.净利润'] |
stockList |
List(必须) |
股票列表:['600000.SH', '000001.SZ'] |
startDate |
Str(必须) |
开始时间:'20171209' |
endDate |
Str(必须) |
结束时间:'20171212' |
report_type |
Str(可选) |
报表时间类型,可缺省,默认是按照数据的公告期为区分取数据,设置为 'report_time' 为按照报告期取数据,' announce_time' 为按照公告日期取数据 |
提示
选择按照公告期取数和按照报告期取数的区别:
报告日期是指财务报告所覆盖的会计时间段,而公告日期是指公司向外界公布该报告的具体时间点
若指定report_type为report_time,则不会考虑财报的公告日期,可能会取到未来数据
若指定report_type为announce_time,则会按财报实际发布日期返回数据,不会取到未来数据
例:
返回值
函数根据stockList代码列表,startDate,endDate时间范围,返回不同的的数据类型。如下:
| 代码数量 | 时间范围 | 返回类型 |
|---|---|---|
| =1 | =1 | pandas.Series (index = 字段) |
| =1 | >1 | pandas.DataFrame (index = 时间, columns = 字段) |
| >1 | =1 | pandas.DataFrame (index = 代码, columns = 字段) |
| >1 | >1 | pandas.Panel (items = 代码, major_axis = 时间, minor_axis = 字段) |
示例
示例
# coding:gbk
def init(C):
pass
def handlebar(C):
#取总股本和净利润
fieldList = ['CAPITALSTRUCTURE.total_capital', '利润表.净利润']
stockList = ["000001.SZ","000002.SZ","430017.BJ"]
startDate = '20171209'
endDate = '20231204'
data = C.get_financial_data(fieldList, stockList, startDate, endDate, report_type = 'report_time')
print(data)
返回值
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 1453 (major_axis) x 2 (minor_axis)
Items axis: 000001.SZ to 430017.BJ
Major_axis axis: 20171211 to 20231204
Minor_axis axis: total_capital to 净利润
用法2
原型
ContextInfo.get_financial_data(tabname, colname, market, code, report_type = 'report_time', barpos)
与用法 1 可同时使用
释义
获取财务数据,方法2
参数
| 字段名 | 类型 | 释义与用例 |
|---|---|---|
tabname |
Str(必须) |
表名:'ASHAREBALANCESHEET' |
colname |
Str(必须) |
字段名:'fix_assets' |
market |
Str(必须) |
市场:'SH' |
code |
Str(必须) |
代码:'600000' |
report_type |
Str(可选) |
报表时间类型,可缺省,默认是按照数据的公告期为区分取数据,设置为 'report_time' 为按照报告期取数据,' announce_time ' 为按照公告日期取数据 |
barpos |
number |
当前 bar 的索引 |
返回值
float :所取字段的数值
示例
示例
# coding:gbk
def init(C):
pass
def handlebar(C):
index = C.barpos
data = C.get_financial_data('ASHAREBALANCESHEET', 'fix_assets', 'SH', '600000', index)
print(data)
返回值
42758000000.0
官方来源
QMT 官方文档:获取财务数据。网页核对日期:2026-10-11。