Calculate Joel Greenblatt’s Magic Formula ranking. Companies are ranked on two measures and the ranks are added; the lowest total combines a good business with a low price:

\[\text{Earnings Yield} = \text{EBIT} / \text{Enterprise Value} (\text{how cheap the company is})\] \[\text{Return on Capital} = \text{EBIT} / (\text{Net Working Capital} + \text{Net Fixed Assets}) (\text{how good the business is})\]

Net working capital excludes cash and short-term debt, so the return on capital measures the operating business. The ranking is across the Toolkit’s tickers, so pass the universe to choose from.

For more information, see the following book:

  • Greenblatt, J. (2006). “The Little Book That Beats the Market.” Wiley.

Also known as: Greenblatt formula, earnings yield and return on capital ranking.

Magic Formula in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_magic_formula as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AAPL", "MSFT", "GOOGL", "META", "INTC"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.models.get_magic_formula().xs("Magic Formula Rank", level=1)

Or, after setting up the Finance Toolkit MCP, ask:

How did Apple, Microsoft, Alphabet, Meta and Intel rank against each other on Greenblatt's Magic Formula from 2021 to 2025?

Which returns:

  2021 2022 2023 2024 2025
AAPL 2 1 1 2 2
GOOGL 4 2 2 1 4
INTC 3 5 5 5 5
META 1 2 2 4 2
MSFT 5 4 4 2 1

Parameters

get_magic_formula accepts the following parameters.

ParameterTypeDescriptionExample
dilutedboolWhether to use the diluted share count for the market capitalization. Defaults to True.False
trailingint | NoneSum the operating income over this many periods (e.g. 4 quarters, a trailing twelve months). The enterprise value and the capital are taken at the period end. Defaults to None, which is 4 for quarterly data (a year of operating income) and 1 otherwise.4
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding.2
show_columnslist[str] | NoneThe periods to show. Defaults to None, all periods.None, all periods
Share