This strategy is based on the investing principles described in Joel Greenblatt’s classic “The Little Book That Beats the Market”. The model selects U.S. stocks by combining value and quality — Greenblatt’s so-called Magic Formula. The backtest presented here runs from 1998 through mid-2025 and is implemented using QuantConnect’s algorithm framework.
This post is part of my ongoing series where I test and share classic factor investing strategies from renowned books. If you haven’t seen it yet, check out my previous post on the PSR & Relative Strength strategy from “What Works on Wall Street”.
The Magic Formula is elegantly simple. It ranks stocks based on two key metrics:
Return on Assets (ROA) – to identify high-quality businesses.
Price-to-Book (PB) ratio – to identify cheap stocks.
The core idea is: buy good companies at bargain prices.
In this implementation, the universe is filtered to include only 1000 Large U.S. stocks traded on NYSE or NASDAQ, with at least 6 months of trading history, and a market capitalization over $50 million. Financials are excluded due to their non-comparable accounting structures. From there, we calculate the ROA and PB ratios for each stock, rank them accordingly, and select the top 25 candidates once per year.
The result is a low-turnover, long-only portfolio that rebalances annually in December, allocating capital equally across all selected stocks.
Over 27+ years, this simple strategy delivered strong risk-adjusted returns:

This strategy turns a $100,000 portfolio into more than $2.6 million, with only one rebalance per year and minimal trading costs. The very low turnover (0.37%) and simple structure make it a great candidate for tax-efficient and low-friction investing.
Strengths
- Combines value and quality into a single, intuitive framework
- Annual rebalance keeps turnover and transaction costs minimal
- Uses liquidity and listing filters to reduce noise and execution issues
- Conceptually straightforward and easy to explain
- Performs well across multiple decades and regimes
Limitations
- Suffers from high daily drawdowns in bear markets (–56.7%)
- Sharpe Ratio of 0.454 suggests moderate risk-adjusted returns
- Excludes macro or momentum signals, so it may underperform in growth-driven or speculative environments
- Sector tilts can emerge due to clustering in "cheap" industries
Joel Greenblatt’s Magic Formula is a brilliant reminder that simple beats complex — especially when it comes to investing. This strategy’s consistent performance over decades, combined with its low complexity and cost-efficiency, makes it a reliable base model for long-term investors.
While it may experience painful drawdowns, its long-term alpha, robust compound returns, and strong fundamentals continue to validate the underlying logic.
If you have thoughts, optimizations, or want to collaborate on ensemble modeling — feel free to reach out or follow me on X @CabedoVestment.
Happy trading!
Mia Alissi
Monthly-universe churn
SelectCoarse()suppresses re-runs ifTime.Month == _lastMonth, but_lastMonthis only updated afterSelectFine()finishes.Result: on the first trading day of every new month Coarse returns a fresh universe unnecessarily, causing one-day churn.
Rebalance timing & scheduling
Scheduleis fired on the last business-day of every month, yet trading occurs only whenTime.Month == 12.→ Inefficient; and if the intent is “rebalance at start of the year” the code instead rebalances at December month-end (a week or more early).
Sector-quota logic in SelectFine()
percent = 1000 / filteredFine.Count.– If
filteredFine.Count < 1000, percent > 1 ⇒ each sector keeps all its stocks, defeating the quota.– If
filteredFine.Count ≫ 1000, percent ≈ 0 andc = Ceil(y.Count * percent)can round to 0, discarding entire sectors.The step is therefore often moot or counter-productive.
Unsafe fundamental access in top25Stocks()
OperationRatios,ValuationRatiosandROAare non-null:Securities[s].Fundamentals.OperationRatios.ROA.ValueAny null will throwNullReferenceExceptionduring live/back-test.Liquidate-then-buy pattern
Liquidate()submits market sells, immediately followed by market buys fromSetHoldings(). Live trading incurs extra spread/slippage and leaves the account 100% cash for several seconds. Prefer a single rebalance order set.Fixed 1/25 allocation
If <25 symbols pass the filters the portfolio is under-invested;
if 0 symbols pass, the preceding
Liquidate()empties the book for the entire year.Sources: 12 Month Cycle In Cross Section Of Stocks Returns, Sector Rotation Based On News Sentiment, Standardized Unexpected Earnings, Accrual Anomaly, Stock Selection Strategy Based On Fundamental Factors
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
CabedoVestment
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!