Playbook
The Magic Formula screen, automated
Joel Greenblatt’s Magic Formula is one of the cleanest ideas in quantitative investing: buy cheap stocks in good businesses, hold for a year, rerank. The edge is real — and so is the discipline tax that most investors refuse to pay. Here is how to encode the screen against a live fundamentals database, what the gotchas are, and how to run it monthly without writing SQL.
The short version
- The Magic Formula buys the intersection of the cheapest stocks (high earnings yield) and the best businesses (high ROIC) — quality and value, combined.
- Out-of-sample testing (2003–2015) showed roughly 11.4%/yr versus about 8.7%/yr for the S&P 500 — but with multi-year stretches of underperformance.
- Greenblatt calls this the discipline tax: the strategy works precisely because most people abandon it during the bad stretches.
- A screen is a candidate list, not a buy list. Factor edges operate in diversified baskets held with discipline, not in cherry-picked names.
The idea: cheap and good
Every value screen asks some form of “is this cheap?” The Magic Formula asks a second question simultaneously: “is this business actually good?” That combination is the whole insight.
Earnings yield is the cheapness measure: EBIT divided by enterprise value (market cap plus net debt). It is the earnings-based cousin of the price-to-earnings ratio, but it uses operating earnings rather than bottom-line net income, and it puts enterprise value in the denominator so capital structure doesn’t distort the comparison across firms. A high earnings yield means you are getting a lot of operating earnings per dollar of total value paid — the company is cheap on that metric.
Return on invested capital (ROIC) is the quality measure: EBIT divided by invested capital (equity plus net debt). It tells you how much operating profit the business generates per dollar of capital the owners and lenders have deployed. A high ROIC signals a business with a real competitive advantage — pricing power, cost advantages, network effects, or some other moat that lets it compound capital above the cost of that capital.
Neither measure alone is sufficient. A cheap stock with terrible returns on capital is a value trap. A high-ROIC business trading at a rich multiple may already have its quality priced in. The Magic Formula ranks every stock on both axes, adds the two ranks, and buys the names where the combined rank is highest. You get quality at a discount.
The record, and the discipline tax
The documented track record is real and worth taking seriously — but only if you read it carefully. Out-of-sample testing over 2003 to 2015 showed roughly 11.4% per year for the Magic Formula approach versus about 8.7% per year for the S&P 500. That is a meaningful spread over more than a decade.
The catch is the texture of those returns. The strategy went through multi-year stretches of underperformance against the index. A basket of cheap, good businesses can lag badly when the market bids up growth and momentum, or when the specific quality signals the screen captures are out of favor. During those stretches, the historically documented returns provide no comfort to an investor watching their portfolio trail a passive fund year after year.
Greenblatt names this the discipline tax explicitly: the edge is real because most investors cannot sit through the bad stretches. They rotate out, they second-guess the formula, they override the output with narrative reasoning. The moment they do, they give up the premium. The discipline is not optional — it is the entire mechanism.
Frame the 11.4% as a base rate, never as a guarantee. Past out-of-sample results reflect a specific time window and market regime. The screen is a systematic starting point, not a mechanism that produces returns on demand.
Build the screen in one query
ClawTerminal’s screen_equities engine stores a query-ready row per US issuer with TTM operating income, balance sheet items and price-derived ratios. Custom ratios accept safe arithmetic over those columns. Here is the full Magic Formula recipe expressed as a query object:
{
"custom_ratios": {
"earnings_yield": "ttm_operating_income / (market_cap + total_debt - cash)",
"roic": "ttm_operating_income / (equity + total_debt - cash)"
},
"rules": [
"market_cap > 500000000",
"ttm_operating_income > 0",
"earnings_yield > 0.05",
"roic > 0.10"
],
"sort": "earnings_yield desc",
"exclude_financials": true
// Pass survivors to a single-name deep dive.
// Save with save_screen; rerun monthly with run_screen.
}
Each rule does specific work:
- market_cap > 500,000,000 — the $500M floor drops micro-caps and nano-caps where liquidity is thin, reported fundamentals are noisier, and position sizing is harder. Greenblatt’s original work used a minimum market cap; the exact threshold is a judgment call based on your strategy size.
- ttm_operating_income > 0 — a negative EBIT means both ratios are negative, which would produce misleading rankings. This rule keeps only profitable businesses in the pool.
- earnings_yield > 0.05 — a 5% earnings yield floor (EBIT/EV) as a minimum cheapness gate. Names below this are either richly priced or have so much net cash that enterprise value approaches zero in unusual ways.
- roic > 0.10 — a 10% ROIC floor as a minimum quality gate. Below this, the business is earning less than most reasonable estimates of its cost of capital.
- sort: earnings_yield desc — after both floors are applied, sort by cheapness to surface the cheapest names that also clear the quality bar. In a full implementation you would rank on a combined earnings-yield + ROIC composite; sorting by earnings_yield descending is a serviceable first approximation that keeps the query simple.
The gotchas that separate a real screen from a garbage one
The formula is simple. The failure modes are not.
EBIT proxy and invested capital
XBRL filings do not always cleanly separate interest expense, so ttm_operating_income is the closest available EBIT proxy — it is above the interest line for most reporters. Invested capital is reconstructed as equity + total_debt - cash, which nets out excess cash on the grounds that cash earns a market rate and is not part of the operating capital base. These are reasonable approximations, not exact replications of Greenblatt’s original definitions.
The free cash flow cross-check
A high earnings yield with negative free cash flow is often a working-capital timing artifact. Retailers in an off-cycle inventory build, contractors with project-timing mismatches, and capital-intensive businesses mid-expansion can all show strong operating income while burning cash. The FCF line strips out that noise.
In ClawTerminal’s data model, ttm_capex is stored as a positive outflow, so free cash flow is computed as ttm_operating_cashflow - ttm_capex (subtract, not add). An optional tightening rule is to add "fcf_yield > 0" to the rules array. Alternatively, include ttm_operating_cashflow in the result columns and eyeball the rows manually before acting on the ranked list.
Always exclude financials
This is not optional. Banks, insurers and REITs report cash, equity and debt on a fundamentally different basis from operating companies. A bank’s “cash” is a liability-side funding instrument; its “debt” is largely deposits. Applying earnings yield and ROIC formulas built for industrial businesses to those balance sheets produces nonsense ratios. Set exclude_financials: true on every run.
Read the row, not just the rank
ROIC can explode when share buybacks shrink equity toward zero — or push it negative in the case of mature consumer companies that have returned more capital than they earned. A tiny or negative equity base inflates the ROIC denominator in ways that have nothing to do with business quality. Before passing any name to a deep dive, eyeball the equity line. If it is unusual, treat the ROIC as an artifact.
Value traps are the systematic failure mode of earnings-yield screens. A stock can be cheap because its business is permanently impaired. The ROIC floor helps, but it does not fully immunize against deteriorating moats. Pair the quant screen with a smart-money overlay and the 13F institutional view to add independent confirmation before committing capital.
Run it with an agent
Once your agent is connected to a markets MCP server, you describe the screen in plain English and let it call the tools. The Magic Formula workflow maps onto three tools:
| Step | Tool | What it does |
|---|---|---|
| Run the screen | screen_equities | Stateless query: custom ratios, rules, sort, exclude_financials. Returns ranked candidate list. |
| Save and rerun | save_screen / run_screen | Persist the query by name; call run_screen monthly to get a fresh ranking against updated fundamentals. |
| Manage | list_screens / delete_screen | See saved screens; clean up stale versions. |
A plain-English version you can paste to a connected agent:
“Run a Magic Formula screen: US stocks over $500M market cap, positive operating income, earnings yield above 5% (EBIT divided by market cap plus net debt), and ROIC above 10% (EBIT divided by equity plus net debt). Exclude financials. Sort by earnings yield descending. For the top 20 results, show me market cap, earnings yield, ROIC, and free cash flow yield. Flag any with negative free cash flow. Save the screen as ‘magic-formula-monthly’ so I can rerun it next month.”
That prompt encodes the two-ratio logic, the floors, the FCF cross-check, and the persistence step. The agent constructs the custom ratio definitions, runs the query, surfaces the candidates, and stores the screen for monthly reruns with run_screen("magic-formula-monthly").
Monthly reranking is the operational discipline that matters most. Fundamentals update quarterly; prices update daily. Re-running the screen every four to six weeks keeps the candidate list anchored to the most recent trailing-twelve-month figures without over-trading on noise.
What not to conclude
- Don’t treat the top-ranked names as a buy list. They are survivors of a quantitative filter — still candidates pending a moat and management check.
- Don’t override the basket logic by concentrating in one or two names that look most compelling narratively. Factor edges operate in diversified exposure, not in concentrated conviction bets.
- Don’t ignore a multi-year underperformance stretch as a signal the formula is “broken.” That stretch is the discipline tax. The historical record was built through exactly those stretches.
- Don’t skip the free-cash-flow cross-check on names with high earnings yield but capital-intensive or working-capital-heavy business models.
- Don’t forget to exclude financials. Every time, on every run.
The Magic Formula is not magic — it is a disciplined, systematic way to look for businesses that are both cheap and good, applied consistently enough that the statistical edge has room to emerge. The screen automates the ranking. The discipline is still on you.