Shortcuts

Financial data#

Security-code queries infer the market on the server and accept no market argument. Unsupported markets raise an error.

Function / class

Purpose

get_pit_financials_ex()

Read quarterly statements and their visible revisions

get_financial_metrics()

Read derived financial metrics on each trading day

Semantics are covered in Financials and share capital; as_of in Restatements and as_of.

libfinance.get_pit_financials_ex(order_book_ids, fields, start_quarter, end_quarter, as_of=None, statements='latest')[source]#

Point-in-time financial statement data.

Parameters
  • order_book_ids – One code or a list

  • fields – Which financial fields; required

  • start_quarter – First quarter, like "2024q1"

  • end_quarter – Last quarter

  • as_of – Use the version known at that point; omit for the latest. Pass this in backtests, or you will use restatements that had not been published yet.

  • statements – "latest" (one row per quarter) or "all" (every revision)

Returns

DataFrame indexed by (order_book_id, quarter), with info_date and if_adjusted alongside the requested fields

Examples

1. The latest visible version

print(lf.get_pit_financials_ex("600000.XSHG", ["total_operating_revenue", "net_income_parent"], "2024q1", "2024q3"))
Output#
                       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);
Output#
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: only what was disclosed by that day

print(lf.get_pit_financials_ex("600000.XSHG", ["net_income_parent"], "2024q1", "2024q3",
                               as_of="2024-11-01", statements="latest"))
Output#
                       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);
Output#
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”: every revision visible then

print(lf.get_pit_financials_ex(["600000.XSHG", "AAPL.US"], ["net_income_parent"], "2024q1", "2024q3",
                               as_of="2024-11-01", statements="all"))
Output#
                                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);
Output#
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]

Output produced by docs/_shared/update_examples.py running the example scripts: data version sha256:6feda8ca, 2026-10-09. Download the example scripts: 07_financials.cpp · 07_financials.py

Reading the result: without as_of, 2024q1 is the 2025 restatement (if_adjusted 1); with as_of="2024-11-01" each quarter is the latest version known then; statements="all" lists every version visible then – 2024q2 has its August disclosure and its October revision.

libfinance.get_financial_metrics(order_book_ids, fields, start_date=None, end_date=None)[source]#

Derived financial metrics, one formula set for CN and US. A trading day’s value comes from the latest report visible after that day’s close: values jump on announcement days and stay flat in between; one the latest report cannot give is NaN.

Parameters
  • order_book_ids – One code or a list

  • fields – Metric names, e.g. roe_lf, revenue_ttm, net_profit_growth_lyr, debt_to_assets_lf

  • start_date – First day; with end_date omitted as well, the latest trading day

  • end_date – Last day

Returns

DataFrame indexed by (order_book_id, date), one column per metric

Examples

1. Daily metrics: they step on announcement days and hold in between

print(lf.get_financial_metrics("600519.XSHG", ["roe_lf", "revenue_ttm"], "2024-10-28", "2024-11-01"))
Output#
                            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);
Output#
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. China and US on the same formulas; no dates means the latest trading day

print(lf.get_financial_metrics(["600519.XSHG", "AAPL.US"], ["net_profit_growth_lyr", "debt_to_assets_lf"]))
Output#
                          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);
Output#
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]

Output produced by docs/_shared/update_examples.py running the example scripts: data version sha256:6feda8ca, 2026-10-09. Download the example scripts: 07_financials.cpp · 07_financials.py