财务报表与因子#
按证券代码查询时由服务端推断市场,无需 market 参数。某个市场没有对应数据能力时会报错。
季度区间决定查哪几期报告,as_of 决定当时已知哪些版本。
回测应设置 as_of;字段与因子名以所连接服务支持的目录为准。详见 财务数据与股本。
函数 / 类 |
解决的问题 |
|---|---|
按季度查询财报,限制披露时点并查看修订版本 |
|
按交易日查询财务衍生指标 |
get_pit_financials_ex — 按季度查询财报,限制披露时点并查看修订版本#
- libfinance.get_pit_financials_ex(order_book_ids, fields, start_quarter, end_quarter, as_of=None, statements='latest')[源代码]#
获取 point-in-time 财务数据。
- 参数
order_book_ids – 单个代码或代码列表
fields – 需要的财务字段
start_quarter – 起始季度,如
"2024q1"end_quarter – 结束季度
as_of – 以该时点已知的版本为准;省略则取最新。回测里应当传入,否则会 用到当时还没发布的修订值。
statements –
"latest"(每个季度取最新那一版)或"all"(返回全部修订版本)
- 返回
pandas.DataFrame,以 (order_book_id, quarter) 为索引,包含 info_date(披露时间,市场当地时间)、 请求的财报字段(概念 id,如
total_operating_revenue、net_income_parent、assets) 和 if_adjusted(1 表示取自后来报告的比较期)。
示例
1. 最新可见版本
print(lf.get_pit_financials_ex("600000.XSHG", ["total_operating_revenue", "net_income_parent"], "2024q1", "2024q3"))
info_date total_operating_revenue net_income_parent if_adjusted
order_book_id quarter
600000.XSHG 2024q1 2025-04-30 4.532800e+10 1.742100e+10 1
2024q2 2026-08-28 8.824800e+10 2.698800e+10 1
2024q3 2025-10-31 1.298390e+11 3.522300e+10 1
show(lf::get_pit_financials_ex("600000.XSHG", {"total_operating_revenue", "net_income_parent"}, "2024q1",
"2024q3"), 0);
order_book_id quarter info_date total_operating_revenue net_income_parent if_adjusted
600000.XSHG 2024q1 2025-04-30 45328000000 17421000000 1
600000.XSHG 2024q2 2026-08-28 88248000000 26988000000 1
600000.XSHG 2024q3 2025-10-31 129839000000 35223000000 1
[3 rows x 6 columns]
2. as_of:只用截至那天已披露的信息
print(lf.get_pit_financials_ex("600000.XSHG", ["net_income_parent"], "2024q1", "2024q3",
as_of="2024-11-01", statements="latest"))
info_date net_income_parent if_adjusted
order_book_id quarter
600000.XSHG 2024q1 2024-04-30 1.742100e+10 0
2024q2 2024-10-31 2.698800e+10 0
2024q3 2024-10-31 3.522300e+10 0
show(lf::get_pit_financials_ex("600000.XSHG", {"net_income_parent"}, "2024q1", "2024q3", "2024-11-01", "latest"), 0);
order_book_id quarter info_date net_income_parent if_adjusted
600000.XSHG 2024q1 2024-04-30 17421000000 0
600000.XSHG 2024q2 2024-10-31 26988000000 0
600000.XSHG 2024q3 2024-10-31 35223000000 0
[3 rows x 5 columns]
3. statements=”all”:当时可见的全部修订版本
print(lf.get_pit_financials_ex(["600000.XSHG", "AAPL.US"], ["net_income_parent"], "2024q1", "2024q3",
as_of="2024-11-01", statements="all"))
info_date net_income_parent if_adjusted
order_book_id quarter
600000.XSHG 2024q1 2024-04-30 00:00:00 1.742100e+10 0
2024q2 2024-08-20 00:00:00 2.698800e+10 0
2024q2 2024-10-31 00:00:00 2.698800e+10 0
2024q3 2024-10-31 00:00:00 3.522300e+10 0
AAPL.US 2024q1 2024-05-02 18:04:25 5.755200e+10 0
2024q2 2024-08-01 18:03:34 7.900000e+10 0
2024q3 2024-11-01 06:01:36 9.373600e+10 0
show(lf::get_pit_financials_ex({"600000.XSHG", "AAPL.US"}, {"net_income_parent"}, "2024q1", "2024q3",
"2024-11-01", "all"), 0);
order_book_id quarter info_date net_income_parent if_adjusted
600000.XSHG 2024q1 2024-04-30 17421000000 0
600000.XSHG 2024q2 2024-08-20 26988000000 0
600000.XSHG 2024q2 2024-10-31 26988000000 0
600000.XSHG 2024q3 2024-10-31 35223000000 0
AAPL.US 2024q1 2024-05-02 18:04:25.000000 57552000000 0
AAPL.US 2024q2 2024-08-01 18:03:34.000000 79000000000 0
AAPL.US 2024q3 2024-11-01 06:01:36.000000 93736000000 0
[7 rows x 5 columns]
输出由 docs/_shared/update_examples.py 运行示例脚本生成:数据版本 sha256:6feda8ca,2026-10-09。
下载示例脚本: 07_financials.cpp · 07_financials.py
结果解读:不传 as_of 时,2024q1 取到的是 2025 年的修订版(if_adjusted 为 1);as_of="2024-11-01" 时每季只给当时最新的一版;statements="all" 把当时可见的版本都列出——2024q2 有 8 月首次披露与 10 月修订两版。
get_financial_metrics — 按交易日查询财务衍生指标#
- libfinance.get_financial_metrics(order_book_ids, fields, start_date=None, end_date=None)[源代码]#
获取财务衍生指标,CN 与 US 同一套公式。
每个交易日的值来自那一天收盘后能看到的最新报告:数值在公告日跳变、其间持平;最新报告算不出的为 NaN, 不退回更早的报告。
- 参数
order_book_ids – 单个代码或代码列表
fields – 指标名,如
roe_lf、revenue_ttm、net_profit_growth_lyr、debt_to_assets_lfstart_date – 起始日期;与 end_date 都省略时取最近一个交易日
end_date – 结束日期
- 返回
pandas.DataFrame,以 (order_book_id, date) 为索引,每个指标一列。
示例
1. 逐交易日的指标:在公告日跳变,其间持平
print(lf.get_financial_metrics("600519.XSHG", ["roe_lf", "revenue_ttm"], "2024-10-28", "2024-11-01"))
roe_lf revenue_ttm
order_book_id date
600519.XSHG 2024-10-28 0.266621 1.652014e+11
2024-10-29 0.266621 1.652014e+11
2024-10-30 0.266621 1.652014e+11
2024-10-31 0.266621 1.652014e+11
2024-11-01 0.266621 1.652014e+11
show(lf::get_financial_metrics("600519.XSHG", {"roe_lf", "revenue_ttm"}, "2024-10-28", "2024-11-01"), 0);
order_book_id date roe_lf revenue_ttm
600519.XSHG 2024-10-28 0.266621 165201382180.390015
600519.XSHG 2024-10-29 0.266621 165201382180.390015
600519.XSHG 2024-10-30 0.266621 165201382180.390015
600519.XSHG 2024-10-31 0.266621 165201382180.390015
600519.XSHG 2024-11-01 0.266621 165201382180.390015
[5 rows x 4 columns]
2. A 股与美股同一套公式;省略日期取最近一个交易日
print(lf.get_financial_metrics(["600519.XSHG", "AAPL.US"], ["net_profit_growth_lyr", "debt_to_assets_lf"]))
net_profit_growth_lyr debt_to_assets_lf
order_book_id date
600519.XSHG 2026-10-09 -0.020290 0.151931
AAPL.US 2026-10-09 0.200132 0.719464
show(lf::get_financial_metrics({"600519.XSHG", "AAPL.US"}, {"net_profit_growth_lyr", "debt_to_assets_lf"}), 0);
order_book_id date net_profit_growth_lyr debt_to_assets_lf
600519.XSHG 2026-10-09 -0.020290 0.151931
AAPL.US 2026-10-09 0.200132 0.719464
[2 rows x 4 columns]
输出由 docs/_shared/update_examples.py 运行示例脚本生成:数据版本 sha256:6feda8ca,2026-10-09。
下载示例脚本: 07_financials.cpp · 07_financials.py