How much of the cash a competitor generates goes to capital spending, dividends and buybacks? Does it lean on borrowing, or sit on a cash pile? This page turns that "use of cash" comparison into a five-year table via an API. The script pulls the cash flow statement, balance sheet and income statement, writes one row per fiscal year, and adds a second CSV that lines up each company's latest year.
The examples use data retrieved from ZENITH Code on October 29, 2026 for Kao (4452, December year-end), Fast Retailing (9983, August year-end) and Toyota Motor (7203, March year-end).
What you will get from this page
- How to join three financial statements by fiscal period into one row per year
- How to follow operating cash flow through its uses by addition alone, keeping outflows negative
- The two common definitions of free cash flow, and a case where they differ by orders of magnitude
- How to keep a missing capex or buyback figure from becoming zero
- Ratios that let you compare companies of very different sizes
Where cash-flow comparisons trip people up
Cash-flow figures are harder to line up than income-statement figures, for three reasons.
- Signs. Cash flow statements show outflows as negative numbers. Capex and dividends are both negative.
- Definitions. Free cash flow means different things in different documents. Mix "operating CF + investing CF" with "operating CF − capex" and you compare two numbers under one name.
- Missing line items. Capex, dividends and buybacks are pulled from individual lines of the statement. Depending on how a company words its headings, some years cannot be extracted.
Through the API, signs arrive as filed and each field has one definition. If you read them by the same rules, the comparison stays consistent.
Endpoints
| Endpoint | Fields used |
|---|---|
/cash-flow-statement |
operatingCashFlow, investingCashFlow, capitalExpenditure, freeCashFlow, dividendsPaid, purchaseOfTreasuryStock, depreciationAndAmortization |
/balance-sheet-statement |
equityRatio, interestBearingDebt, netInterestBearingDebt, cashAndCashEquivalents |
/income-statement |
revenue (the denominator for size-neutral ratios) |
Each costs one token per call. period=annual&limit=5 returns five fiscal years. That is three tokens per company, or 18 for six companies.
Join the three statements by fiscal period
The script runs on Node.js 18 or later with no extra packages. It fetches the three statements and merges them by fiscalPeriod.
// cash-allocation.mjs (node cash-allocation.mjs)
import { writeFileSync } from "node:fs";
const BASE = "https://api.zenithcode.net/stable";
const API_KEY = process.env.ZENITH_API_KEY ?? "YOUR_API_KEY";
async function get(path, params) {
const res = await fetch(`${BASE}${path}?${new URLSearchParams(params)}`, {
headers: { "x-api-key": API_KEY },
});
// Stop on any failure rather than put a partial table in front of a meeting
if (!res.ok) throw new Error(`${path} ${params.symbol}: HTTP ${res.status}`);
return res.json();
}
const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : null);
async function fiveYears(symbol) {
const q = { symbol, period: "annual", limit: 5 };
const sources = { is: await get("/income-statement", q),
bs: await get("/balance-sheet-statement", q),
cf: await get("/cash-flow-statement", q) };
const years = new Map();
for (const [key, rows] of Object.entries(sources)) {
for (const row of rows) {
if (row.symbol !== symbol) throw new Error(`row for another company: ${row.symbol}`);
const y = years.get(row.fiscalPeriod) ?? { fiscalPeriod: row.fiscalPeriod };
if (y[key]) throw new Error(`two rows for one period: ${key} ${row.fiscalPeriod}`);
y[key] = row;
years.set(row.fiscalPeriod, y);
}
}
return [...years.values()].sort((a, b) => a.fiscalPeriod.localeCompare(b.fiscalPeriod));
}
The three calls go out one after another with await. If a fiscal period appears twice, or a row belongs to another company, the script builds no table for that company.
Follow operating cash flow without flipping signs
For each year, the script breaks down where the cash went. Because it keeps the API's signs (outflows negative), a running total is just addition.
function allocation(y) {
const cf = y.cf ?? {}, bs = y.bs ?? {}, is = y.is ?? {};
const ocf = num(cf.operatingCashFlow), icf = num(cf.investingCashFlow);
const capex = num(cf.capitalExpenditure); // negative (purchase of PP&E)
const dividends = num(cf.dividendsPaid); // negative
const buybacks = num(cf.purchaseOfTreasuryStock); // negative
const fcf = num(cf.freeCashFlow) ?? (ocf !== null && icf !== null ? ocf + icf : null);
const both = (a, b) => (a !== null && b !== null);
const row = {
fiscalPeriod: y.fiscalPeriod,
standard: cf.accountingStandard ?? bs.accountingStandard ?? null,
consolidation: cf.consolidation ?? null,
ocf, icf, capex,
otherInvesting: both(icf, capex) ? icf - capex : null, // investing CF other than capex
ocfAfterCapex: both(ocf, capex) ? ocf + capex : null, // the "operating CF − capex" form
fcf, // operating CF + investing CF
dividends, buybacks,
// Shareholder returns is shown as a positive amount (the one column with flipped sign)
shareholderReturns: both(dividends, buybacks) ? -(dividends + buybacks) : null,
depreciation: num(cf.depreciationAndAmortization),
equityRatio: num(bs.equityRatio),
netDebt: num(bs.netInterestBearingDebt),
revenue: num(is.revenue),
};
row.afterReturns = both(fcf, row.shareholderReturns) ? fcf - row.shareholderReturns : null;
return row;
}
A value that could not be retrieved stays null, and anything computed from it is null too. In a year with no buyback figure, total shareholder returns and the amount left after returns are both blank.
Treating null as zero would make the company look as if it bought back no shares, and would overstate what was left after returns. A blank cell looks untidy, but in a meeting it is safer to see that a number is missing.
Ratios for companies of different sizes
Raw amounts side by side only show you the biggest company. To compare competitors, use proportions.
function ratios(r) {
const div = (a, b) => (a === null || b === null || b <= 0 ? null : a / b);
return {
...r,
ocfMargin: div(r.ocf, r.revenue), // operating CF ÷ revenue
capexToOcf: r.capex === null ? null : div(-r.capex, r.ocf), // capex ÷ operating CF
returnsToFcf: div(r.shareholderReturns, r.fcf), // returns ÷ free CF
};
}
No ratio is computed when the denominator is zero or negative. In a year of negative free cash flow, "returns ÷ free CF" would come out negative and read backwards.
Write the CSVs
Finally, the script collects five years per company into one file and writes a second file with each company's latest year only.
const COLS = ["symbol", "fiscalPeriod", "standard", "consolidation", "revenue", "ocf", "capex",
"otherInvesting", "ocfAfterCapex", "fcf", "dividends", "buybacks", "shareholderReturns",
"afterReturns", "depreciation", "equityRatio", "netDebt", "ocfMargin", "capexToOcf", "returnsToFcf"];
const cell = (v) => (v === null || v === undefined ? "" : typeof v === "number" ? String(v)
: `"${String(v).replace(/"/g, '""')}"`);
const all = [];
for (const symbol of ["4452", "9983", "7203"]) { // one company at a time
for (const y of await fiveYears(symbol)) all.push({ symbol, ...ratios(allocation(y)) });
}
const latest = [...new Map(all.map((r) => [r.symbol, r])).values()]; // last row per company
const toCsv = (rows) => [COLS.join(","), ...rows.map((r) => COLS.map((c) => cell(r[c])).join(","))].join("\n");
writeFileSync("cash-allocation-5y.csv", "" + toCsv(all));
writeFileSync("cash-allocation-latest.csv", "" + toCsv(latest));
Amounts are in yen, ratios are 0–1 decimals, and signs follow the API (capex and dividends negative, shareholder returns positive). Missing values are blank, never zero. The leading keeps Excel from garbling the file.
Sample output 1: Kao, fiscal year ended December 2025
Following operating cash flow step by step (in ¥100 million):
| Step | Amount | Running total |
|---|---|---|
| Operating CF | 1,996.8 | 1,996.8 |
| Capex | −612.1 | 1,384.7 |
| Other investing | −85.5 | 1,299.1 (free CF) |
| Dividends paid | −711.5 | 587.6 |
| Treasury share purchases | −800.5 | −212.9 (after returns) |
Shareholder returns totaled ¥151.20 billion. Relative to free cash flow, that is 1.164 in the CSV and 116.4% on screen. Because the running total ends below zero, Kao returned more than its free cash flow to shareholders that year.
Sample output 2: the free cash flow definition changes the answer
Fast Retailing's fiscal year ended August 2025 shows how far the two definitions can diverge.
| Step | Amount (¥100 million) |
|---|---|
| Operating CF | 5,806.2 |
| Capex | −1,355.4 |
Operating CF − capex (ocfAfterCapex) |
4,450.8 |
| Other investing | −4,433.9 |
Free CF (fcf, operating CF + investing CF) |
17.0 |
Counted as operating CF minus capex, free cash flow is ¥445.08 billion. Under the API's definition it is ¥1.70 billion. The gap is "other investing," the part of investing cash flow that is not capex. It may include securities or deposits moving in and out, intangible assets or acquisitions; this table cannot tell you which. Check the line items in the cash flow statement.
The CSV carries both columns so you can match definitions before you put your figure next to an internal report or a broker's "free cash flow."
Sample output 3: equity ratio and net debt
| Company | Fiscal year | Equity ratio | Change | Net debt (¥100 million) |
|---|---|---|---|---|
| Kao | Ended December 2025 | 56.7% | −0.4 pt | −801.4 |
| Toyota Motor | Ended March 2026 | 37.8% | −0.6 pt | 305,458.5 |
Negative net debt means cash exceeds interest-bearing debt (a net cash position). Fast Retailing was also net cash for the fiscal year ended August 2026, at −¥419.23 billion. Write changes in a ratio as percentage points. In the CSV, Kao's equity ratio is 0.567.
Even though all three were fetched on the same day, their latest years end in December 2025, August 2026 and March 2026, up to eight months apart. When you present a latest-year comparison, keep the fiscal period column.
Reading the numbers correctly
Free cash flow is operating CF plus investing CF
freeCashFlow is the sum of operating and investing activities in the cash flow statement. It is not "minus capex," so purchases and sales of securities and subsidiary shares within investing cash flow are included. It is null if either total is missing.
Capex is the purchase of property, plant and equipment line only
capitalExpenditure is the value of the "purchase of property, plant and equipment" line and excludes intangibles. Companies whose heading combines the two, such as "purchase of non-current assets," have no tangible-only line, so the field is null. Toyota's capex and treasury share purchases were null in all five years retrieved. Null means the line could not be extracted, not that nothing was spent.
As a result, Toyota's rows have blank "other investing" and "operating CF − capex." What you can use is total investing cash flow (−¥4.9988 trillion for the fiscal year ended March 2024) and free cash flow (−¥792.38 billion for the same year). In a chart, draw investing CF as one bar and do not label it "capex."
Do not divide capex by depreciation
depreciationAndAmortization includes amortization of intangibles and, under IFRS, depreciation of right-of-use (leased) assets. Its scope differs from capex limited to property, plant and equipment, so a ratio of the two runs low for companies that lease stores or equipment. The script places the two side by side and does not divide them. For Fast Retailing's fiscal year ended August 2026, capex was −¥79.91 billion and depreciation ¥237.25 billion.
Segment capex will not match
Capex in the segment note is the increase in property, plant and equipment and intangible assets: a different scope, and an increase rather than a cash payment. It normally does not match cash-flow capex. For the business-by-business view, see comparing segment revenue and profit.
Interest-bearing debt includes lease liabilities
interestBearingDebt is the company's disclosed interest-bearing debt plus lease liabilities; without a disclosed figure, it sums borrowings, bonds, commercial paper, lease liabilities and similar items. Under IFRS most leases sit on the balance sheet, so companies that rent stores or equipment can show more debt than Japanese GAAP peers. It is 0 when the balance sheet has no borrowing lines and null when this cannot be determined. Net debt is null for banks and securities firms, where deposits and client assets make it meaningless.
The business model changes what debt means
Toyota's net debt of ¥30.55 trillion includes borrowing by its financial services business. Put a company with a finance arm next to a pure manufacturer or retailer on the same yardstick and a business difference starts to look like a financial one.
Consolidated or parent-only can differ by statement within one year
Each row's consolidation says whether figures are consolidated (consolidated) or parent-only (nonconsolidated). In the year a company first acquires a subsidiary at period end, the annual report has a consolidated balance sheet but parent-only income and cash flow statements. In that year, the balance sheet row is consolidated and the cash flow row is parent-only. That is why the CSV keeps a consolidation column.
Non-yen filers and newly listed companies
For companies whose statements are in a currency other than yen (for example 6269 and 9399 in US dollars), amounts are null and the row carries reportedCurrency and nullReason (non_jpy_material); the API does not convert currencies. For newly listed companies, the prior-year row built from the first post-listing kessan tanshin has no income or cash flow figures, only a balance sheet. The three statements may therefore return different numbers of years.
Dividends paid are cash paid in that year
dividendsPaid is the total cash paid out as dividends during the year, which runs on a different timetable from dividends declared for the fiscal year. Per-share dividends, and dividend yields that combine them with share prices, are outside the scope of this page.
Adapting it to your company
- To reconcile opening and closing cash, add
effectOfForexChangesOnCash(exchange-rate effects) andcashBalanceAdjustmentsto the three activity totals. - For a quarterly deck, save the JSON responses to files and reuse them for the same fiscal period. The numbers only change with new filings.
- To view five years for one company on a screen, try the company deep-dive template. Its saved demo opens without an API key.
Related
- API docs: cash flow statement, balance sheet, income statement, metric definitions
- Related articles: Build a peer benchmarking table, Compare competitors' segment revenue and profit, Accounting standards in Japan
- Templates: zenith-code-examples
- Data display rights
An illustrated series on the same material is on Qiita (in Japanese).
This page explains how to handle financial data. It is not a recommendation to buy or sell any security.