BLOG

Behind the numbers.

Code examples, market analysis, and data quality deep-dives.

What Growth Rate Is the Market Pricing In? Reverse DCF in Python
Does a Strong Balance Sheet Cushion Drawdowns? Leverage and Downside Risk in Python
Does Ticker Recycling Corrupt a Mean-Reversion Backtest? Entity-Resolved Z-Scores in Python
How Much of a Growth Screen's Backtested Edge Is Survivorship Bias? Point-in-Time Index Testing in Python
Why Do Leveraged ETFs Decay? Measuring Volatility Drag in Python
Are Consumer Staples Margins Shrinking Under Inflation? Gross Margin Trend Analysis in Python
Do Weak Jobs Reports Predict Market Drawdowns? NFP Surprise Event Study in Python
Is the Rotation From Tech to Industrials Backed by Earnings? Relative EPS Growth Analysis in Python
Is the Semiconductor Rally Broadening Beyond NVIDIA? Return Dispersion Analysis in Python
Which Stocks Benefit Most When Oil Prices Fall? Oil Beta Screening in Python
Do Bond Returns Predict Stock Returns? Granger Causality Test in Python
Which Stocks Actually Drive Portfolio Returns? Shapley Value Attribution in Python
Does "Sell in May" Still Work? Calendar Anomaly Backtest in Python
How to Build Complete Price History Through Ticker Changes? Entity Resolution in Python
Are KO and PEP Cointegrated? Pairs Trading Signal Construction in Python
Which Commodities Have the Strongest Momentum? Rotation Backtest in Python
Which Commodity ETFs Have the Worst Tail Risk? Expected Shortfall in Python
Are Gold Miners Leveraged Gold Bets? Rolling Beta Analysis in Python
Does the Base-Metals-to-Gold Ratio Lead Cyclical Stocks? Signal Test in Python
Can Risk Parity Tame Commodity Volatility? Portfolio Optimization in Python
Are Power Stocks Becoming an AI Infrastructure Trade? Momentum Screening in Python
Which AI Chip Stocks Have Margin Momentum? Profitability Trend Analysis in Python
Which AI Stocks Are Cheapest Relative to Growth? Growth-Adjusted Valuation in Python
Does AI Stock Leadership Persist? Momentum Backtest in Python
Which AI Stocks Have the Cleanest Balance Sheets? Net Cash Screening in Python
Can Risk Parity Reduce Mega-Cap Drawdowns? Portfolio Optimization in Python
Which Growth Stocks Are Self-Funding? Cash-Flow Quality Screening in Python
Which Sectors Struggle When the Dollar Rallies? Sector Rotation Analysis in Python
Do Cheap Stocks Hold Up When Bonds Sell Off? Valuation Rotation in Python
Does the Nasdaq 100 Have Better Growth Quality Than the Dow? Index Constituent Analysis in Python
Do Healthcare Cash-Flow Margins Predict Returns? Signal Evaluation in Python
Which Dividend Stocks Survive a Cash-Flow Stress Test? Dividend Screening in Python
Does Heavy Insider Selling Predict Weak Returns? Insider Flow Test in Python
Can Quality Screens Reduce Small-Cap Balance-Sheet Risk? Russell 2000 Test in Python
Which Retailers Have Positive Operating Leverage? Margin Screening in Python
Is MSTR a Leveraged Bitcoin Proxy? Rolling Beta Analysis in Python
Is Micron's Memory Cycle Recovering? Inventory and Margin Forecasting in Python
Which Sectors Work When Bonds Rally? Rate-Sensitive Rotation in Python
Do One-Month Price Extremes Reverse? Signal Evaluation in Python
Do Low-Volatility S&P 500 Stocks Reduce Drawdowns? Factor Test in Python
Is AI Capex Paying Back Fast Enough? Revenue Hurdle Forecasting in Python
Could Shorter AI Asset Lives Hit Earnings? Depreciation Stress Test in Python
How Much AI Capex Risk Can a Portfolio Remove? Constrained Optimization in Python
Is the AI Capex Trade Crowded? Rolling Volatility and Sector Rotation in Python
Did the AI Boom Come From Existing S&P 500 Members? Point-in-Time Momentum Test in Python
Is AI Revenue Circular? Customer-Vendor Capex Loop Analysis in Python
Is the AI Trade Connected to Private Credit? Rolling Correlation Network in Python
Is Apollo More Balance-Sheet Sensitive Than Peers? Leverage Screen in Python
Are AI Earnings Supported by Cash Flow? Accrual and Capex Screen in Python
Can Defensive Stocks Hedge AI Drawdowns? Basket Regime Test in Python
How Fast Does the Market Price In Fed Decisions? FOMC Event Study in Python
How Much Are Options Sellers Overpaid? The Variance Risk Premium in Python
Which Companies Have the Worst Earnings Quality? Sloan Accrual Screen with Geographic Revenue Data in Python
Does the Oil-to-Gold Ratio Signal Recessions? XLE/GLD Backtest in Python
Is AI Spending Crowding Out Free Cash Flow? Capex Sustainability Across the Mag 7 in Python
Does a Long Energy / Short Bonds Portfolio Capture Inflation Surprises? Factor Construction in Python
Can a Hidden Markov Model Detect Oil Market Regimes? HMM Analysis in Python
Do Grain Prices Predict Food Inflation? Granger Causality Test in Python
Does the Corporate Credit Spread Predict Stock Market Crashes? BAA-AAA Spread Analysis in Python
Do Oil Stocks Hedge Inflation? Rolling Beta Analysis in Python
Which Stocks Are Most Rate-Sensitive? Equity Duration via Bond Beta in Python
Which Companies Have the Highest Accrual Ratios? Earnings Quality Screening in Python
Is Alpha Persistent or Decaying? Rolling Sharpe Ratio Analysis in Python
Are Markets Trending or Mean-Reverting? Hurst Exponent Analysis in Python
Is Consumer Discretionary vs Staples a Leading Indicator? XLY/XLP Ratio Analysis in Python
Does Heavy Capex Predict Future Stock Returns? Capital Expenditure Analysis in Python
How to Estimate Cost of Equity Using CAPM in Python
Is Volatility Predictable? Testing for Volatility Clustering in Python
Which Industrials Are Overleveraged? Net Debt to EBITDA Screening in Python
GM Before and After Bankruptcy: Why Entity Resolution Matters for Financial Data
What Is Adjusted Beta? Merrill Lynch Beta Shrinkage in Python
How Good Is a Stock Pick? Information Ratio and Tracking Error in Python
Do Stock Returns Follow a Normal Distribution? Testing for Fat Tails in Python
Which Large Caps Have the Highest Free Cash Flow Yield? FCF Screening in Python
Which Sectors Won Over 5 Years? Sector Rotation Analysis in Python
How to Forecast Stock Volatility with GARCH Models in Python
Are Stock Prices Mean-Reverting? Augmented Dickey-Fuller Test in Python
How to Calculate CAPM Alpha and Beta with Regression in Python
How to Compare Sector Sharpe Ratios and Sortino Ratios in Python
DELL: Why Stitching Historical Price Data Together Is Wrong
How to Analyze Drawdown and Recovery for Bank Stocks in Python
How to Screen SaaS Stocks by Revenue Growth and Cash Flow in Python
How to Screen REITs by Dividend Yield and Valuation in Python
How Correlated Are the Magnificent 7? Intra-Group Correlation in Python
AAPL vs XOM: Do Individual Stocks Have Seasonal Patterns?
How to Rank Large-Cap Stocks by Momentum in Python
How to Build a Multi-Endpoint Financial Dashboard in Python
How to Compare Volatility Across Energy Stocks in Python
How to Screen Healthcare Stocks by Valuation in Python
How to Build a Sector Correlation Matrix for Portfolio Diversification in Python
How to Find Oversold and Overbought Stocks Using Z-Scores in Python
How to Measure Earnings Quality: Cash Flow vs Net Income in Python
How to Build a Multi-Factor Stock Screen in Python (Value + Momentum + Quality)
How to Build a Simple DCF Model for Any Stock in Python
How to Screen Tech Stocks by Revenue Growth in Python
How to Screen Stocks by Balance Sheet Health in Python
Is "Sell in May" Real? SPY Monthly Seasonality Over 10 Years
How to Compare Sector Performance YTD Using Python
How to Track S&P 500 Additions and Removals Over Time in Python
How to Screen Dividend Stocks by Yield and Quality in Python
How to Calculate Max Drawdown and Recovery Time for Any Stock in Python
How to Compare Profitability Across Mega-Cap Tech Stocks in Python
Why Ticker Symbols Are Unreliable: The Recycling Problem Every Quant Should Know
How to Calculate and Compare Stock Volatility in Python
How to Screen Blue-Chip Stocks by P/E Ratio in Python
How to Track Companies Through Ticker Changes, Bankruptcies, and Renames in Python
S&P 500 Turnover: How Much the Index Has Changed Since 2010
How to Calculate Stock Beta and Correlation in Python
← All articles

How Much of a Growth Screen's Backtested Edge Is Survivorship Bias? Point-in-Time Index Testing in Python

What's the question?

A growth screen ranks companies by revenue growth and buys the fastest growers. Testing one requires a universe, and most people reach for the index as it looks today. That choice rigs the test: today’s S&P 500 members survived and grew enough to still be there, while firms acquired or destroyed are absent and recent joiners are present because they had already won. Screening "high growth in 2021, hold to 2026" over that list guarantees the winners are in the sample.

Survivorship bias is the name for this distortion, usually asserted rather than measured. The question is how large it is: run one identical screen over two universes differing only in whether membership is point-in-time or contaminated. The return gap is the survivorship premium.

The approach

xfl.index("sp500", as_of="2021-06-30") returns membership as it stood on that date, including firms later removed; without as_of, today’s.

  1. Take the S&P 500 on 30 June 2021 (honest universe) and on 16 July 2026 (contaminated).
  2. Size the difference: count the names present then but gone now.
  3. Screen both identically — top decile by revenue growth over the last fiscal year public at formation.
  4. Hold to 16 July 2026, equal-weighted, against the S&P 500 itself.

Two details decide the result. The first is lookahead: growth must be knowable at formation, so the screen uses the last fiscal year ending on or before 31 March 2021 — a 90-day reporting lag. Only restated figures exist here; the top-decile picks were verified against filings.

The second is the crux: names that leave. Dropping one because its price series ends reintroduces the bias being measured. Every name is held from formation to its last available price; if it stops trading, the proceeds redeploy equally across survivors. Nothing is discarded. Here the rule never handles a termination — all 48 point-in-time picks still trade — but it absorbs one data gap: FIS has a 16-month hole, treated as a pause; excluding it moves the headline to 978 basis points.

"Left the index" rarely means failure: of the 75 leavers, 30 stopped trading, mostly through acquisition. Another 44 still trade — including First Republic, seized in May 2023, now changing hands as FRCB at a fraction of a cent — and one is unreachable by ticker. Entity-keyed matching captures that near-total loss.

Code

import xfinlink as xfl
import pandas as pd

xfl.set_api_key("YOUR_API_KEY")  # free at https://xfinlink.com/signup

FORM, END = "2021-06-30", "2026-07-16"

pit = xfl.index("sp500", as_of=FORM)   # membership AS IT STOOD in June 2021
now = xfl.index("sp500")               # membership today
pit_e, now_e = set(pit["entity_id"]), set(now["entity_id"])

# Revenue growth from the last fiscal year public at formation (90-day lag)
allt = sorted(set(pit["ticker"]) | set(now["ticker"]))
fund = pd.concat([xfl.fundamentals(allt[i:i+40], period_type="annual", fields=["revenue"],
                                   start="2018-01-01", end="2021-03-31")
                  for i in range(0, len(allt), 40)], ignore_index=True)

rows = []
for eid, g in fund[fund["revenue"].notna()].sort_values("period_end").groupby("entity_id"):
    g = g.drop_duplicates("period_end", keep="last")
    if len(g) < 2:
        continue
    t0, t1 = g.iloc[-1], g.iloc[-2]
    if not (300 <= (t0["period_end"] - t1["period_end"]).days <= 430) or t1["revenue"] <= 0:
        continue
    rows.append({"entity_id": eid, "growth": t0["revenue"] / t1["revenue"] - 1})
gr = pd.DataFrame(rows)

def screen(universe):
    g = gr[gr["entity_id"].isin(universe)]
    return set(g.nlargest(int(round(len(g) * 0.10)), "growth")["entity_id"])

s_pit, s_now = screen(pit_e), screen(now_e)

# prices() caps at 50,000 rows and truncates silently — chunk the request
tick = sorted(pd.concat([pit, now]).drop_duplicates("entity_id")
              .set_index("entity_id").loc[sorted(s_pit | s_now), "ticker"])
px = pd.concat([xfl.prices(tick[i:i+25], start="2021-06-25", end=END,
                           fields=["close", "return_daily"])
                for i in range(0, len(tick), 25)], ignore_index=True)
px["date"] = pd.to_datetime(px["date"])
px = px[px["entity_id"].isin(s_pit | s_now)]          # entity guard: recycled tickers
investable = set(px[px["date"] == FORM]["entity_id"])  # must be buyable at formation
wide = px[(px["date"] > FORM) & (px["date"] <= END)].pivot_table(
    index="date", columns="entity_id", values="return_daily")

def backtest(ids):
    # equal weight across names still trading; leavers' proceeds redeploy to survivors
    r = wide[[c for c in wide.columns if c in ids & investable]].mean(axis=1, skipna=True)
    cum = (1 + r.fillna(0)).cumprod()
    yrs = (cum.index[-1] - cum.index[0]).days / 365.25
    return cum, cum.iloc[-1] ** (1 / yrs) - 1

cum_pit, cagr_pit = backtest(s_pit)
cum_now, cagr_now = backtest(s_now)
print(f"honest {cum_pit.iloc[-1]-1:.2%} ({cagr_pit:.2%}/yr)   "
      f"naive {cum_now.iloc[-1]-1:.2%} ({cagr_now:.2%}/yr)   "
      f"gap {(cagr_now-cagr_pit)*1e4:.0f} bp/yr")

Full script with formatting and visualisation: growth-screen-survivorship-bias-python.py

Output

Point-in-time versus survivorship-contaminated growth screen returns, with index churn by sector
S&P 500 members on 2021-06-30: 499
S&P 500 members on 2026-07-16: 499
In the 2021 index, gone today: 75
In today's index, absent in 2021: 75
  of those 75: 44 still have a live price series, 30 stopped trading (acquired, taken private or failed),
  1 unreachable by ticker (recycled to an unrelated company)

Screenable (revenue history available): point-in-time 481/499, today 489/499
Naive screen picks that were NOT index members at formation: 16/49
    MRNA  MODERNA INC                    FY growth +1234%
    HOOD  ROBINHOOD MARKETS INC          FY growth +247%
    DASH  DOORDASH INC                   FY growth +226%
    COIN  COINBASE GLOBAL INC            FY growth +139%
    SQ    BLOCK INC                      FY growth +101%
    CRWD  CROWDSTRIKE HOLDINGS INC       FY growth +82%

                                          total     CAGR
Honest screen (point-in-time)     n=48    52.57%    8.74%
Naive screen (today's index)      n=48   138.22%   18.79%
  picks common to both            n=33    89.31%   13.50%
  honest-screen-only picks        n=15    -7.39%   -1.51%
  naive-screen-only picks         n=15   242.67%   27.68%
S&P 500 ETF (SPY)                 n=1     84.52%   12.92%

SURVIVORSHIP PREMIUM: +85.65% over the window, +1005 bp per year

Sector labels resolved: members 498/499, removed 74/75, added 75/75

Index churn by sector:
                         in_2021  removed  added  churn_rate
Communication Services       22      6.0      4    0.454545
Information Technology       63      9.0     18    0.428571
Consumer Discretionary       58     16.0      6    0.379310
Energy                       21      3.0      4    0.333333
Financials                   73     10.0     12    0.301370
Materials                    28      5.0      3    0.285714
Health Care                  64     11.0      6    0.265625
Industrials                  76      8.0     11    0.250000
Real Estate                  30      3.0      4    0.233333
Consumer Staples             35      3.0      4    0.200000
Utilities                    28      0.0      3    0.107143

What this tells us

The survivorship premium is 1,005 basis points per year — 85.65 percentage points over five years. Same screen, same date, same rules; the only difference is which list the screen could look at.

The direction of the error matters more than its size. Measured honestly, the screen returned 8.74% a year against the S&P 500’s 12.92% — losing to a passive index fund by 418 basis points. Measured naively, it returned 18.79% and appears to beat the index by 587. The backtest does not overstate a real edge; it manufactures one where the truth is negative.

The decomposition locates the damage. The 33 shared picks returned 89.31%, roughly the index. The 15 held only by the honest screen returned −7.39%; the naive screen’s 15 exclusive picks returned 242.67%. And 16 of the 49 naive picks were not members at formation: Moderna joined three weeks later, Palantir in 2024, AppLovin and Carvana in 2025.

The dominant channel is therefore not failures being deleted but winners being inserted. Committees add companies that have already succeeded, so today’s membership is assembled with knowledge of the future. Deletion contributes less: removal is mostly acquisition, and acquired companies leave at a premium.

So what?

The universe is part of the strategy, not background scenery. A backtest built on today’s constituent list is not a weak test of a growth screen; it tests a different strategy — one that knew which companies the committee would later admit. Reconstruct membership at each formation date, and let names leave when they did.

Contamination scales with churn, so a sector-tilted screen inherits phantom edge in proportion to its tilt. Churn runs from 45% in Communication Services to 11% in Utilities, across the 498 of 499 members carrying a sector label, and the mechanisms differ: Information Technology added 18 names while losing 9, whereas Consumer Discretionary lost 16 and added 6. Apparent alpha gaps across sectors may measure index turnover rather than signal.

Two safeguards cost little: key on entity identifiers rather than tickers, and confirm bulk requests were not truncated — this pull spans 80,802 rows against a 50,000-row default cap.

Built with xfinlink — free financial data API for Python. pip install xfinlink

Built with xfinlink — free financial data API for Python. pip install xfinlink
← All articles