Tools: get_financials · Calls: 5

Ask an assistantLink to this section

Using Fundalyze, compare the gross, operating and net margins of Apple, Microsoft, Alphabet, Amazon and Meta for the last five fiscal years. Show one table per margin, companies as rows, and note that their fiscal years end in different months.

The assistant makes one get_financials call per company with metrics set to the three margin keys, so each answer stays small.

Or in codeLink to this section

Margins come precomputed as ratios (0.45 = 45%), so there is no arithmetic to do. The data dictionary lists every key; gross_margin, operating_margin and net_margin are on the income statement.

import os

import requests

BASE = "https://api.fundalyze.ai/api/public/v1"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['FUNDALYZE_API_KEY']}"

TICKERS = ["AAPL", "MSFT", "GOOGL", "AMZN", "META"]
MARGINS = ["gross_margin", "operating_margin", "net_margin"]

table = {}  # (margin, ticker) -> {fiscal year: value}
for ticker in TICKERS:  # one call at a time per key
    response = session.get(
        f"{BASE}/get_financials",
        params={"ticker": ticker, "statement": "income", "metrics": MARGINS, "years": 5},
        timeout=60,
    )
    response.raise_for_status()
    data = response.json()["data"]
    for metric in data["metrics"]:
        table[metric["key"], ticker] = dict(zip(data["periods"], metric["values"]))

for margin in MARGINS:
    print(f"\n{margin}")
    for ticker in TICKERS:
        cells = table[margin, ticker]
        print(ticker.ljust(6), "  ".join(f"{year} {value:6.1%}" for year, value in cells.items() if value is not None))

Read it carefullyLink to this section

  • Fiscal years differ. FY2025 is the fiscal year the company reports, which for Microsoft ends in June and for Apple in late September. period_ends in data gives each column's end date; compare like with like.
  • Some lines do not exist for some companies. Banks and insurers have no gross margin; the value is null.
  • Check any figure on the page in link, which opens the company's statements on fundalyze.ai.

This page as Markdown, for language models and scripts: /developers/md/recipes/compare-margins