ClearViewLesson libraryWhat's new

The Analyst’s Course · Quant SQL

Factor Scores — Building a Composite Rank in SQL

9 min read · 3 graded checkpoints

The factor context, briefly

Three decades of academic and practitioner work (Fama-French 1992; the 2015 five-factor extension; quality and momentum branches) documents persistent return premia: cheap beats expensive (value), small beats large (size), winners keep winning short-term (momentum), high-quality balance sheets beat junk (quality, Novy-Marx, 2013). The premia are real, modest, cyclical, and subject to long droughts (value's 2010–2020 lost decade). A composite screener is you, running your own small factor model.

The SQL construction

Score each factor within the universe so units cancel: for value, cheaper is better — score_v = CASE WHEN pe IS NOT NULL THEN -pe ELSE NULL END (negative, so lower P/E ranks higher). For quality: score_q = roe. For momentum: score_m = momentum_3m. Combine: SELECT symbol, (0.4*(-pe) + 0.3*roe + 0.3*momentum_3m) AS composite FROM stocks WHERE pe IS NOT NULL AND roe IS NOT NULL ORDER BY composite DESC. The weights (0.4/0.3/0.3) are your thesis — change them and watch the ranking reorder. That sensitivity is not a bug: it is the honest demonstration that factor models are choices, not discoveries.

Momentum's crash problem

Momentum is the strongest short-term factor and has a documented catastrophe mode: Daniel & Moskowitz (2016) show that in sharp market recoveries after crashes (2009, 2020), prior losers rip violently upward and momentum portfolios — short the losers — suffer crashes of their own (2009: the momentum factor lost ~70% in months). Practical translation: never run momentum naked. The composite helps precisely because quality and value weightings blunt the factor's worst mechanism.

composite = w_v·(−PE) + w_q·ROE + w_m·Momentum₃ₘ

Composite factor score — Rank within-universe, weights sum to 1, NULL rows excluded — the simulator below lets you move the weights live.

Case study

2009: the momentum crash in one quarter

Post-Lehman lows, the market ripped: the most beaten-down junk (banks at $1, automakers at $0.50) doubled and tripled in weeks. Momentum strategies, by construction short exactly those names, suffered their worst episode on record — the factor lost roughly 70% in months (Daniel-Moskowitz). Every factor has an environment that kills it; momentum's is the violent recovery. The composite screener's diversification across factors is not style — it is survival engineering.

What you'll practise

In the composite, value enters as −PE because…

3 graded checkpoints · certification exam at the end of the track

Sources

Fama & French (1992, 2015); Daniel & Moskowitz (2016); screener traps per standard practice

Run this in the app →

Learn content is for education only — not individualized financial advice, a recommendation, or a solicitation to buy or sell any security. Options involve substantial risk. Examples are simplified and historical patterns never guarantee future results.