Gross Margin
Calculate the gross margin, a profitability ratio that measures the percentage of revenue that exceeds the cost of goods sold.
The gross margin ratio is calculated by subtracting the cost of goods sold (COGS) from the total revenue and then dividing the result by the total revenue. It represents the portion of revenue that contributes to covering other expenses and generating profit.
The formula is as follows:
\[\text{Gross Margin Ratio} = (\text{Revenue} - \text{Cost of Goods Sold}) / \text{Revenue}\]Gross margin shows pricing power and production cost before overheads, and is best compared within an industry and over time. What sits in cost of goods sold differs between companies (some include depreciation, freight or warehousing, others report them lower down), so small gaps between peers can be accounting rather than economics. The trend matters most: a steady decline points to rising input costs that cannot be passed on, or to a shift in the sales mix.
Also known as: gross profit margin, gross profit percentage.
Gross Margin in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_gross_margin as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["MC.PA", "RMS.PA", "CFR.SW"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.ratios.get_gross_margin()
Or, after setting up the Finance Toolkit MCP, ask:
How did the gross margins of LVMH, Hermès and Richemont develop from 2021 to 2025?
Which returns:
| 2021 | 2022 | 2023 | 2024 | 2025 | |
|---|---|---|---|---|---|
| CFR.SW | 0.627 | 0.6874 | 0.6808 | 0.6691 | 0.644 |
| MC.PA | 0.6829 | 0.6844 | 0.688 | 0.6703 | 0.6624 |
| RMS.PA | 0.6558 | 0.6603 | 0.7229 | 0.7026 | 0.7111 |
Parameters
get_gross_margin accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
growth | bool | Whether to calculate the growth of the ratios. Defaults to False. | True |
lag | int | list[int] | The lag to use for the growth calculation. Defaults to 1. | 4 |
compound | bool | Whether the growth is the compound annual growth rate over the lag (e.g. lag=5 for the five-year CAGR) instead of the total change. Defaults to False. | False |
standardize | bool | Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. | True |
trailing | int | The number of periods to sum flows (income and cash flow statement items) over, with balance sheet items averaged over the same number of period ends. E.g. 4 with quarterly data gives the trailing twelve months (TTM) and 3 with annual data a three-year cumulative figure. Defaults to None, which uses single-period flows (per quarter and not annualized with quarterly data). | 4 |