Financial ratios from SEC filings, with the formula and source
Get margins, ROE, leverage, free cash flow and growth for any listed company from its XBRL filings, with the formula, inputs and accession behind every number.
A ratio from a data vendor is hard to trust because you cannot see its inputs. The /v1/financial-ratios endpoint computes ratios from the company's XBRL facts and returns the formula, each input, its XBRL tag and the accession of the filing it came from.
Setup
import os
import requests
H = {"Authorization": "Bearer " + os.environ["SECFEED_KEY"]}
BASE = "https://secfeedapi.com/v1"
One company, latest fiscal year
r = requests.get(BASE + "/financial-ratios", headers=H, params={"ticker": "AAPL", "limit": 1}).json()
p = r["periods"][0]
print(p["end"])
for name in ("netMargin", "returnOnEquity", "debtToEquity", "currentRatio", "freeCashFlow", "revenueGrowthYoY"):
x = p["ratios"][name]
print(name, x["value"], "=", x["formula"])
Output from a real run:
2026-09-26
netMargin 0.276035 = netIncome / revenue
returnOnEquity 1.422567 = netIncome / average equity
debtToEquity 0.785241 = debt / equity
currentRatio 1.0232 = assetsCurrent / liabilitiesCurrent
freeCashFlow 136056000000 = operatingCashFlow - capex
revenueGrowthYoY 0.150598 = revenue / revenue one year earlier - 1
Each ratio also has an inputs object. For netMargin it holds the net income and revenue values, the XBRL tags used (NetIncomeLoss, RevenueFromContractWithCustomerExcludingAssessedTax) and the accession of the 10-K, so you can open the filing and compare.
Quarterly and trailing twelve months
Pass period=quarterly or period=ttm. A fourth quarter is derived as the fiscal year minus the first nine months, and a TTM value sums four contiguous quarters. Derived values are flagged with derived and list the accessions they used.
r = requests.get(BASE + "/financial-ratios", headers=H, params={"ticker": "AAPL", "period": "ttm", "limit": 1}).json()
Banks and missing inputs
Not every company reports every input. A bank has no cost of revenue, so its gross margin is null with a reason instead of a guess:
r = requests.get(BASE + "/financial-ratios", headers=H, params={"ticker": "JPM", "limit": 1}).json()
x = r["periods"][0]["ratios"]["grossMargin"]
print(x["value"], x["reason"])
None no gross profit or cost of revenue reported (banks, insurers, some utilities)
The line items behind the ratios
/v1/key-metrics returns the standardised line items (revenue, net income, assets, debt, operating cash flow, capex, shares and more), each with its tag and accession. Fiscal years are read from the period dates, so a company with a June year end, such as Microsoft, is reported as June.
There are no price-based ratios such as P/E or dividend yield: SecFeed has no market prices.