量化投资研究服务平台的基本面数据目前包括balance sheet, income statement 和 cashflow statement。
基本步骤
取财务数据一般可以通过3步,先初始化,然后load, 再get, e.g:
fb = FinancialFeed(universe_ticker='000300.SH', begin_day=20140101,
end_day=20160101, report_types=['cashflow_statement'])
fb.load_feed()
cashflow_statement = fb.get_financial_report()
参数说明:
universe_ticker
: 取数据的范围,可以是指数,e.g.’0003000.SH’ 也可以是ticker的list. 如果是None, 代表取全A股的行情begin_day
: 取数据的开始日期,int格式,e.g. 20170717end_day
: 取数据的截止日期,int格式,e.g. 20170717report_types
: list of financial report type, e.g: [‘balance_sheet’, ‘income_statement’, ‘cashflow_statement’]query_method
: 查询类型,默认announce,即公布日,也可以是report, 截止日kwargs
: 关键字参数, 若kwargs.keys()包括data_source, 则data_source取传入的kwargs[‘data_source’], 否则从data_provider.env.DATA_SOURCE取
[1]:
from __future__ import print_function, unicode_literals
import pandas as pd
import datetime
from data_provider.datafeed.financial_feed import FinancialFeed
[2]:
# universe_ticker: 取数据的范围,可以是指数,e.g. ‘0003000.SH’,
# 这表示指数内的所有股票的集合;也可以是ticker的集合,如[‘600000.SH’, ‘000001.SZ’]
universe_ticker = ["000001.SZ", "000002.SZ", "000009.SZ"]
begin_day = 20160101
end_day = 20170731
# report_type, ['balance_sheet', 'cashflow_statement', 'income_statement'] 中的1-3个
report_types = ["balance_sheet", "income_statement", "cashflow_statement"]
fb = FinancialFeed(
universe_ticker=universe_ticker,
begin_day=begin_day,
end_day=end_day,
report_types=report_types,
)
# 执行load
fb.load_feed()
****************** getting financial_info ******************
###### getting balance_sheet info ######
###### getting income_statement info ######
###### getting cashflow_statement info ######
1、合并资产负债表
[3]:
# financial_info是一个数祖,item顺序内容对应report_types中基本面数据的顺序::
balance_sheet = fb.financial_info[0]
print(balance_sheet.name)
balance_sheet.iloc[:10, :]
# 返回的字段adjust的值1表示调整后, 0表示调整前
balance_sheet
accounting_standard | accounts_payable | accounts_payable_in_advance | accrued_expenses | adjust | advance_payment | announceDate | billsPayable | bonds_payable | dataReportPeriod | … | fixedAssets | ticker | totalAssets | currentAssets | currentLiabilities | totalEquity | totalLiabilities | totalLongLiabilities | motherEquity | reportDate | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 新 | 1.883000e+09 | 0.000000e+00 | 0.0 | 1 | 0.000000e+00 | 2016-03-10 | 0.000000e+00 | 4.175000e+10 | 20151231 | … | 0.0 | 000001.SZ | 2.186459e+12 | 0.000000e+00 | 0.000000e+00 | 1.309490e+11 | 2.055510e+12 | 0.000000e+00 | 1.309490e+11 | 2014-12-31 |
1 | 新 | 4.400000e+07 | 0.000000e+00 | 0.0 | 0 | 0.000000e+00 | 2016-03-10 | 0.000000e+00 | 2.129630e+11 | 20151231 | … | 0.0 | 000001.SZ | 2.507149e+12 | 0.000000e+00 | 0.000000e+00 | 1.615000e+11 | 2.345649e+12 | 0.000000e+00 | 1.615000e+11 | 2015-12-31 |
10 | 新 | 9.144646e+10 | 2.126257e+11 | 0.0 | 0 | 3.964697e+10 | 2016-03-14 | 1.674473e+10 | 1.901581e+10 | 20151231 | … | 0.0 | 000002.SZ | 6.112956e+11 | 5.470244e+11 | 4.200618e+11 | 1.363096e+11 | 4.749860e+11 | 5.492412e+10 | 1.001835e+11 | 2015-12-31 |
8 | 新 | 6.704720e+10 | 1.817493e+11 | 0.0 | 1 | 2.943313e+10 | 2016-03-14 | 2.129189e+10 | 1.161223e+10 | 20151231 | … | 0.0 | 000002.SZ | 5.084088e+11 | 4.648057e+11 | 3.456540e+11 | 1.158936e+11 | 3.925151e+11 | 4.686111e+10 | 8.816457e+10 | 2014-12-31 |
3 | 新 | 1.910000e+08 | 0.000000e+00 | 0.0 | 0 | 0.000000e+00 | 2016-04-21 | 0.000000e+00 | 2.473600e+11 | 20160331 | … | 0.0 | 000001.SZ | 2.681155e+12 | 0.000000e+00 | 0.000000e+00 | 1.875690e+11 | 2.493586e+12 | 0.000000e+00 | 1.875690e+11 | 2016-03-31 |
13 | 新 | 9.204379e+10 | 2.510861e+11 | 0.0 | 0 | 4.276716e+10 | 2016-04-28 | 1.147951e+10 | 2.197358e+10 | 20160331 | … | 0.0 | 000002.SZ | 6.588375e+11 | 5.898796e+11 | 4.568986e+11 | 1.387489e+11 | 5.200886e+11 | 6.318995e+10 | 1.006367e+11 | 2016-03-31 |
22 | 新 | 1.355882e+09 | 3.751057e+08 | 0.0 | 0 | 1.534499e+08 | 2016-04-29 | 2.374994e+08 | 2.793701e+09 | 20160331 | … | 0.0 | 000009.SZ | 1.877401e+10 | 1.267394e+10 | 7.736345e+09 | 6.768997e+09 | 1.200502e+10 | 4.268672e+09 | 4.467273e+09 | 2016-03-31 |
20 | 新 | 1.345212e+09 | 3.511338e+08 | 0.0 | 0 | 8.880326e+07 | 2016-04-29 | 2.351834e+08 | 1.792420e+09 | 20151231 | … | 0.0 | 000009.SZ | 1.811490e+10 | 1.253447e+10 | 8.204491e+09 | 6.592099e+09 | 1.152280e+10 | 3.318306e+09 | 4.472156e+09 | 2015-12-31 |
19 | 新 | 1.271117e+09 | 4.140235e+08 | 0.0 | 1 | 9.248348e+07 | 2016-04-29 | 1.563528e+08 | 1.787293e+09 | 20151231 | … | 0.0 | 000009.SZ | 1.472550e+10 | 1.014725e+10 | 6.150755e+09 | 5.464128e+09 | 9.261367e+09 | 3.110612e+09 | 3.277534e+09 | 2014-12-31 |
4 | 新 | 3.000000e+06 | 0.000000e+00 | 0.0 | 0 | 0.000000e+00 | 2016-08-12 | 0.000000e+00 | 3.076030e+11 | 20160630 | … | 0.0 | 000001.SZ | 2.800983e+12 | 0.000000e+00 | 0.000000e+00 | 1.917000e+11 | 2.609283e+12 | 0.000000e+00 | 1.917000e+11 | 2016-06-30 |
2、合并利润分配表
[4]:
income_statement = fb.financial_info[1]
print(income_statement.name)
income_statement[:10]
income_statement
accounting_standard | adjust | announceDate | basicEPS | dataReportPeriod | deadline | diluted_EPS | financial_expenses | incomeTax | main_business_profit | … | cost | operating_expenses | revenue | operatingProfit | remarks | ticker | totalCost | totalRevenue | totalProfit | reportDate | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 新 | 1 | 2016-03-10 | 1.440 | 20151231 | 20141231 | 1.440 | 0.000000e+00 | 6.392000e+09 | 3.577500e+10 | … | 4.716100e+10 | 0.000000e+00 | 7.340700e+10 | 2.624600e+10 | 000001.SZ | 4.716100e+10 | 7.340700e+10 | 2.619400e+10 | 2014-12-31 | |
4 | 新 | 0 | 2016-03-10 | 1.560 | 20151231 | 20151231 | 1.560 | 0.000000e+00 | 6.981000e+09 | 5.270900e+10 | … | 6.726800e+10 | 0.000000e+00 | 9.616300e+10 | 2.889500e+10 | 000001.SZ | 6.726800e+10 | 9.616300e+10 | 2.884600e+10 | 2015-12-31 | |
18 | 新 | 0 | 2016-03-14 | 1.640 | 20151231 | 20151231 | 1.640 | 4.777358e+08 | 7.853180e+09 | -1.561311e+11 | … | 1.381506e+11 | 4.138274e+09 | 1.955491e+11 | 3.312278e+10 | 000002.SZ | 1.659883e+11 | 1.955491e+11 | 3.380262e+10 | 2015-12-31 | |
12 | 新 | 1 | 2016-03-14 | 1.430 | 20151231 | 20141231 | 1.430 | 6.408395e+08 | 5.964839e+09 | -1.157238e+11 | … | 1.025571e+11 | 4.521889e+09 | 1.463880e+11 | 2.497936e+10 | 000002.SZ | 1.255789e+11 | 1.463880e+11 | 2.525236e+10 | 2014-12-31 | |
1 | 新 | 1 | 2016-04-21 | 0.410 | 20160331 | 20150331 | 0.410 | 0.000000e+00 | 1.808000e+09 | 1.062600e+10 | … | 8.473000e+09 | 0.000000e+00 | 2.067100e+10 | 7.447000e+09 | 000001.SZ | 8.473000e+09 | 2.067100e+10 | 7.437000e+09 | 2015-03-31 | |
6 | 新 | 0 | 2016-04-21 | 0.430 | 20160331 | 20160331 | 0.430 | 0.000000e+00 | 1.943000e+09 | 1.567600e+10 | … | 1.951800e+10 | 0.000000e+00 | 2.753200e+10 | 8.014000e+09 | 000001.SZ | 1.951800e+10 | 2.753200e+10 | 8.029000e+09 | 2016-03-31 | |
21 | 新 | 0 | 2016-04-28 | 0.075 | 20160331 | 20160331 | 0.075 | 2.418153e+08 | 4.374452e+08 | -1.123304e+10 | … | 9.967697e+09 | 7.265958e+08 | 1.461131e+10 | 1.646601e+09 | 000002.SZ | 1.334969e+10 | 1.461131e+10 | 1.687269e+09 | 2016-03-31 | |
14 | 新 | 1 | 2016-04-28 | 0.059 | 20160331 | 20150331 | 0.059 | 4.434333e+07 | 2.762389e+08 | -6.624001e+09 | … | 5.870110e+09 | 6.872442e+08 | 8.894338e+09 | 1.169823e+09 | 000002.SZ | 8.086334e+09 | 8.894338e+09 | 1.184265e+09 | 2015-03-31 | |
29 | 新 | 1 | 2016-04-29 | 0.030 | 20160331 | 20150331 | 0.030 | 5.375799e+07 | 2.135085e+07 | 2.932674e+08 | … | 5.945829e+08 | 9.553999e+07 | 9.033160e+08 | 1.169121e+08 | 000009.SZ | 8.934318e+08 | 9.066971e+08 | 1.270414e+08 | 2015-03-31 | |
32 | 新 | 0 | 2016-04-29 | 0.500 | 20151231 | 20151231 | 0.500 | 2.469733e+08 | 2.704462e+08 | 1.518030e+09 | … | 3.238027e+09 | 5.296555e+08 | 4.865351e+09 | 1.149742e+09 | 000009.SZ | 4.771966e+09 | 4.895401e+09 | 1.236345e+09 | 2015-12-31 |
3、合并现金流量表
[5]:
cashflow_statement = fb.financial_info[2]
print(cashflow_statement.name)
cashflow_statement[:10]
cashflow_statement
accounting_standard | adjust | intangibel_amort | longterm_amort | announceDate | longterm_asset_paid_cash | dataReportPeriod | deadline | fix_asset_depreciation | finance_cashflow | cash_flows_yield | ticker | reportDate | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 新 | 1 | 631000000.0 | 3.320000e+08 | 2016-03-10 | 3.835000e+09 | 20151231 | 20141231 | 6.280000e+08 | 3.118900e+10 | 2.532100e+10 | 000001.SZ | 2014-12-31 |
4 | 新 | 0 | 623000000.0 | 4.230000e+08 | 2016-03-10 | 3.534000e+09 | 20151231 | 20151231 | 7.250000e+08 | 1.741770e+11 | -1.826000e+09 | 000001.SZ | 2015-12-31 |
18 | 新 | 0 | 0.0 | 2.256451e+08 | 2016-03-14 | 2.063001e+09 | 20151231 | 20151231 | 4.901612e+08 | -5.103911e+09 | 1.604602e+10 | 000002.SZ | 2015-12-31 |
12 | 新 | 1 | 0.0 | 1.728757e+08 | 2016-03-14 | 1.830746e+09 | 20151231 | 20141231 | 3.760286e+08 | -1.961725e+10 | 4.172482e+10 | 000002.SZ | 2014-12-31 |
1 | 新 | 1 | 0.0 | 0.000000e+00 | 2016-04-21 | 1.251000e+09 | 20160331 | 20150331 | 0.000000e+00 | 3.505500e+10 | 1.149500e+10 | 000001.SZ | 2015-03-31 |
6 | 新 | 0 | 0.0 | 0.000000e+00 | 2016-04-21 | 2.360000e+08 | 20160331 | 20160331 | 0.000000e+00 | 5.188000e+10 | 5.926800e+10 | 000001.SZ | 2016-03-31 |
21 | 新 | 0 | 0.0 | 0.000000e+00 | 2016-04-28 | 1.075726e+08 | 20160331 | 20160331 | 0.000000e+00 | 7.208145e+09 | -1.072613e+10 | 000002.SZ | 2016-03-31 |
14 | 新 | 1 | 0.0 | 0.000000e+00 | 2016-04-28 | 1.660793e+07 | 20160331 | 20150331 | 0.000000e+00 | -6.990299e+09 | -1.534442e+10 | 000002.SZ | 2015-03-31 |
29 | 新 | 1 | 0.0 | 0.000000e+00 | 2016-04-29 | 1.320711e+08 | 20160331 | 20150331 | 0.000000e+00 | -9.257662e+06 | -1.094725e+08 | 000009.SZ | 2015-03-31 |
32 | 新 | 0 | 13979060.8 | 5.166250e+07 | 2016-04-29 | 8.555720e+08 | 20151231 | 20151231 | 1.552177e+08 | 1.771429e+09 | 1.258639e+07 | 000009.SZ | 2015-12-31 |