BLOG

Behind the numbers.

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

Which S&P 500 Companies Are Closest to Default? Merton Distance-to-Default in Python
What Happens to Stocks Removed From the S&P 500? Replacement Pair Analysis in Python
Does the Golden Cross Work? 50/200 Moving Average Crossover Backtest in Python
Financial Data for Academic Finance Research
Does Skipping the Most Recent Month Improve Momentum? S&P 500 Decile Sorts in Python
Does Cointegration Survive Out of Sample? Pairs Trading Validation in Python
Which Dividends Are Not Covered by Cash? Free-Cash-Flow Coverage Screening in Python
GICS vs SIC vs NAICS: Which Industry Classification to Use
How Many Stocks Does It Take to Diversify? Random Portfolio Simulation in Python
How Many Days of Data Does a Volatility Estimate Need? Range-Based Estimators in Python
How Much of S&P 500 Cash Flow Is Stock Compensation? Cross-Sectional Analysis in Python
What Is a 13F Filing? Institutional Holdings Explained
Does Revenue Growth Explain Profit Growth? Cross-Sectional Decomposition in Python
How Much of the Nasdaq 100 Is Already in the S&P 500? Index Overlap Analysis in Python
How Often Does a 99% Value-at-Risk Limit Actually Break? VaR Backtesting in Python
Real-Time vs End-of-Day Market Data: Which Do You Need?
How Concentrated Are S&P 500 Earnings? Point-in-Time Index Analysis in Python
Does Volatility Scale With the Square Root of Time? Variance Ratio Test in Python
Does Goodwill Distort the Price-to-Book Screen? Goodwill-Adjusted Valuation in Python
How Are Shares Outstanding Reported (and Why They Disagree)
Do Low-Volatility Stocks Deliver Better Risk-Adjusted Returns? S&P 500 Quintile Sorts in Python
Does Trend Following Beat Buy and Hold? Time-Series Momentum in Python
Has the Stock-Bond Correlation Flipped? 60/40 Portfolio Risk in Python
What API to Use for a Stock Screener
Which Assets Hedge Inflation Shocks? Macro Factor Betas in Python
Does Covariance Shrinkage Beat the Sample Covariance? Minimum-Variance Portfolios in Python
Do Faster Inventory Turns Mean Thinner Margins? Gross Margin Return on Inventory in Python
SEC EDGAR API vs Fundamentals API: Which to Use
Does Fast Earnings Growth Persist? Rank Correlation Analysis in Python
Split Adjustment Explained: Adjusted Close vs Close
Which Trading Day of the Month Pays Best? Turn-of-the-Month Analysis in Python
Can You Use Yahoo Finance Data Commercially?
How Many Independent Bets Does a Nine-Sector Portfolio Give You? Eigenvalue Analysis in Python
Which Volatility Forecast Wins One Month Ahead? HAR vs EWMA in Python
How Concentrated Are Institutional Equity Portfolios? Form 13F Concentration Analysis in Python
Do Stocks Earn Their Returns Overnight or Intraday? Return Decomposition in Python
When Do Corporate Insiders Actually Trade? Form 4 Timing Analysis in Python
Data Requirements for Backtesting a Trading Strategy
What Is Survivorship Bias in Backtesting?
Do High Dividend Yields Come From Bigger Payouts or Falling Prices? Yield Decomposition in Python
Do Stocks Fall Harder Than They Rise? Downside Beta vs Upside Beta in Python
Does Volatility Targeting Improve Sharpe Ratios? Seven-Asset Backtest in Python
Free Stock Market Data APIs: What You Actually Get
How to Give an LLM Financial Data With an MCP Server
Does Post-Earnings Announcement Drift Survive Real Filing Dates? PEAD Event Study in Python
Do Insider Buying Clusters Predict Returns? Signal Testing in Python
Does the S&P 500 Index Effect Still Exist? Event Study in Python
Are Companies Leaving the S&P 500 Faster Than They Used To? Index Survival Analysis in Python
Does Gross Profitability Predict Stock Returns? Quintile Factor Test in Python
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 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

Which S&P 500 Companies Are Closest to Default? Merton Distance-to-Default in Python

What’s the question?

A lender owns a claim that pays in full unless the company fails; a shareholder owns whatever is left afterwards. Merton (1974) turned that ordering into an option: equity is a call on the firm’s assets, struck at the face value of the debt. Cover the debt and shareholders keep the remainder; fall short and they hand the firm to its lenders.

The output is distance to default, the number of standard deviations of asset value separating a firm from its default point. It combines two things usually looked at separately: the debt on the balance sheet, and how violently the assets move in value. The question is whether the combination reorders the S&P 500 against a plain leverage screen, or reproduces it with extra arithmetic.

The approach

Asset value and asset volatility are not observable. Both are solved from the market value of equity, its volatility, and the reported debt.

  1. Take current S&P 500 members outside financials and real estate, where the assumption of a simple debt structure holds up. Companies without reported long-term debt leave the sample.
  2. Set the default point to debt due within one year plus half of longer-dated debt, the Moody’s KMV convention; long-dated debt need not be repaid at the horizon, so counting all of it overstates the barrier. Filers differ over what that line holds, so the noncurrent figure from the filing is used where a company reports it inclusive of the current portion, and a company reporting no noncurrent long-term debt for the quarter leaves the sample.
  3. Build a one-year daily path of equity value from the latest market capitalisation and the split-adjusted close, then solve E = V·N(d1) − F·e^(−rT)·N(d2) for asset value V at each date given a trial asset volatility, recompute asset volatility from the solved values, and repeat until the two agree. Convergence took at most eight passes.
  4. Read off distance to default at the last date, using the one-year Treasury yield of 3.77% on 5 August 2026 as the drift.
  5. Screen the panel first: at least 200 trading sessions, no session-to-session move beyond 45% in log terms, which marks a spin-off rather than a return, and a market capitalisation within 15% of shares times price.

Every company named below was checked against its own filings on the SEC’s XBRL interface.

Code

import numpy as np, pandas as pd, xfinlink as xfl
from scipy.stats import norm

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

R, T = 0.0377, 1.0

def asset_value(E, F, sigma_V, r=R, t=T):
    """Invert E = V N(d1) - F exp(-rt) N(d2) for V, one V per equity observation."""
    V = E + F
    for _ in range(100):
        sq = sigma_V * np.sqrt(t)
        d1 = (np.log(V / F) + (r + 0.5 * sigma_V ** 2) * t) / sq
        gap = V * norm.cdf(d1) - F * np.exp(-r * t) * norm.cdf(d1 - sq) - E
        step = gap / np.maximum(norm.cdf(d1), 1e-8)
        V = np.maximum(V - step, E * 1.000001)
        if np.max(np.abs(step) / V) < 1e-12:
            break
    return V

def merton(E, F, r=R, t=T):
    sigma_E = np.diff(np.log(E)).std(ddof=1) * np.sqrt(252)
    sigma_V = sigma_E * E[-1] / (E[-1] + F)          # KMV starting guess
    for _ in range(300):
        V = asset_value(E, F, sigma_V, r, t)
        new = np.diff(np.log(V)).std(ddof=1) * np.sqrt(252)
        if abs(new - sigma_V) < 1e-10:
            sigma_V = new
            break
        sigma_V = new
    V = asset_value(E, F, sigma_V, r, t)
    dd = (np.log(V[-1] / F) + (r - 0.5 * sigma_V ** 2) * t) / (sigma_V * np.sqrt(t))
    return V[-1], sigma_V, dd, norm.cdf(-dd)

members = xfl.index("sp500")["ticker"].dropna().tolist()
fun = xfl.fundamentals(members, period_type="quarterly", start="2025-09-01",
                       fields=["current_portion_long_term_debt", "long_term_debt"])
latest = fun.sort_values("period_end").groupby("ticker").tail(1).set_index("ticker")
latest["F"] = latest["current_portion_long_term_debt"].fillna(0) + 0.5 * latest["long_term_debt"]

mcap = xfl.metrics(list(latest.index), period_type="daily", fields=["market_cap"],
                   start="2026-07-27")
px = xfl.prices(list(latest.index), period="1y", fields=["adj_close"])

for tk, s in latest.iterrows():
    path = px[px["ticker"] == tk].sort_values("date")["adj_close"].values
    E0 = mcap[mcap["ticker"] == tk].sort_values("period_end")["market_cap"].iloc[-1]
    V, sigma_V, dd, pdef = merton(E0 * path / path[-1], s["F"])
    print(f"{tk:6} asset vol {sigma_V:5.2f}  leverage {s['F'] / V:5.2f}  DD {dd:6.2f}")

Full script with formatting and visualisation: merton-distance-to-default-sp500-python.py

Output

S&P 500 companies plotted by debt share of asset value against asset volatility, with contours of constant distance to default
============================================================================================================
MERTON DISTANCE TO DEFAULT | S&P 500 excluding financials and real estate | as at 2026-08-05
============================================================================================================
Equity as a one-year call on assets, strike = default point, risk-free rate 3.77% (1-year Treasury, 5 Aug 2026)
Default point = debt due within one year + half of longer-dated debt (KMV convention)
Asset value and asset volatility solved jointly from 1 year of daily equity values

S&P 500 members outside financials and real estate with reported debt    358
  with market capitalisation, share count and closing price             345
  with at least 200 trading sessions in the window                      343
  with no session-to-session move beyond 45% in log terms               340
  market capitalisation within 15% of shares x price                    340
Filing quarters used: 2025-12-31 to 2026-07-04

TWELVE SHORTEST DISTANCES TO DEFAULT
      company                              equity   default  equity  asset    F/V     DD  implied  leverage
                                               $m  point $m     vol    vol                default      rank
------------------------------------------------------------------------------------------------------------
CHTR  CHARTER COMMUNICATIONS INC           18,399    47,479    0.50   0.17   0.74   1.88    3.00%         1
SMCI  SUPER MICRO COMPUTER INC             18,234     2,330    0.92   0.82   0.11   2.28    1.13%       125
NCLH  NORWEGIAN CRUISE LINE HLDGS LTD       9,321     8,088    0.54   0.30   0.47   2.48    0.65%         4
KMX   CARMAX INC                            8,042     8,798    0.58   0.25   0.53   2.58    0.49%         2
LITE  LUMENTUM HOLDINGS INC                59,243     3,260    0.93   0.84   0.05   3.12    0.09%       226
NRG   N R G ENERGY INC                     25,390    12,384    0.48   0.35   0.33   3.12    0.09%        13
CZR   CAESARS ENTERTAINMENT INC DE          6,131     5,958    0.49   0.22   0.50   3.19    0.07%         3
ORCL  ORACLE CORP                         415,843    61,171    0.64   0.58   0.13   3.28    0.05%       106
BLDR  BUILDERS FIRSTSOURCE INC              8,162     2,302    0.50   0.41   0.22   3.55    0.02%        50
DOW   DOW INC                              21,384     9,420    0.44   0.31   0.31   3.75    0.01%        21
CCL   CARNIVAL CORP                        40,637    13,180    0.47   0.36   0.25   3.85    0.01%        40
VST   VISTRA CORP                          47,527    10,531    0.50   0.43   0.18   3.88    0.01%        68

TEN HEAVIEST DEBT LOADS, AND WHERE THE MODEL PUTS THEM
      company                         sector                        F/V  asset vol     DD  DD rank
------------------------------------------------------------------------------------------------------------
CHTR  CHARTER COMMUNICATIONS INC      Communication Services       0.74       0.17   1.88        1
KMX   CARMAX INC                      Consumer Discretionary       0.53       0.25   2.58        4
CZR   CAESARS ENTERTAINMENT INC DE    Consumer Discretionary       0.50       0.22   3.19        7
NCLH  NORWEGIAN CRUISE LINE HLDGS LTD Consumer Discretionary       0.47       0.30   2.48        3
PCG   P G & E CORP                    Utilities                    0.47       0.14   5.65       53
EIX   EDISON INTERNATIONAL            Utilities                    0.46       0.14   5.83       56
ES    EVERSOURCE ENERGY               Utilities                    0.37       0.16   6.29       78
EXC   EXELON CORP                     Utilities                    0.36       0.12   8.36      160
CAG   CONAGRA BRANDS INC              Consumer Staples             0.36       0.20   5.12       41
WYNN  WYNN RESORTS LTD                Consumer Discretionary       0.35       0.24   4.46       25

SECTOR MEDIANS
sector                      names     F/V  asset vol      DD
------------------------------------------------------------
Information Technology         62   0.035      0.449    6.86
Communication Services         15   0.138      0.281    7.14
Materials                      26   0.088      0.283    7.94
Consumer Staples               30   0.104      0.234    8.11
Consumer Discretionary         38   0.077      0.293    8.34
Energy                         20   0.120      0.276    8.49
Health Care                    50   0.092      0.283    8.77
Utilities                      29   0.278      0.137    9.55
Industrials                    70   0.062      0.278   10.53

Ranking agreement across 340 companies
  Spearman, DD against leverage                      0.514
  Spearman, DD against asset volatility              0.448
  Names in both the riskiest 20 by DD and by leverage    6 of 20
  Riskiest by leverage only: CAG, CMCSA, CMS, CPB, DTE, DUK, EIX, ES, EXC, FE, PCG, PNW, VZ, WYNN
  Riskiest by DD only:       APTV, BLDR, CCL, DOW, INTC, KLAC, LITE, LYB, MOS, ON, ORCL, SMCI, UAL, VST
  Distance to default: median 8.61, 5th percentile 4.07, 95th 16.48

SENSITIVITY OF THE RANKING
  risk-free rate 2%                  mean |change| in DD  0.04   riskiest-20 held 20 of 20   Spearman 1.000
  risk-free rate 6%                  mean |change| in DD  0.05   riskiest-20 held 20 of 20   Spearman 1.000
  default point + short-term debt    mean |change| in DD  0.40   riskiest-20 held 18 of 20   Spearman 0.983
  6-month estimation window          mean |change| in DD  0.99   riskiest-20 held 17 of 20   Spearman 0.962

What this tells us

The two rankings disagree. Distance to default and leverage correlate at 0.514 across 340 companies, and only 6 of the 20 names flagged riskiest by one measure appear in the other’s twenty. Position on the plane fixes distance to default, so the grey curves on the chart are lines of equal credit risk, and they bend sharply: a company moves along one by trading debt for volatility. Charter Communications sits at the bottom right, the heaviest debt load in the sample at 74% of asset value against a cable network’s 17% asset volatility. Super Micro Computer sits at the top left, debt at 11% of assets and asset volatility at 82%. Both land inside a distance to default of 2.3.

Utilities make the point in aggregate. They carry the most debt, a median of 27.8% of asset value against 3.5% in information technology, and the model still ranks them second safest, because their median asset volatility of 13.7% is under a third of technology’s 44.9%.

The implied probabilities deserve less weight than the ordering. A risk-neutral 3.00% for Charter sits far above what its bond spreads imply, since the calculation prices default risk rather than forecasting it, and the model grants the firm one maturity and no refinancing. Bharath and Shumway (2008) found the ordering carries the predictive content, not the level.

The sensitivity checks say the ordering is stable. Moving the risk-free rate between 2% and 6% shifts distance to default by 0.05 on average and leaves the riskiest 20 untouched; adding short-term borrowings to the default point costs 0.40 and keeps 18. Halving the estimation window costs 0.99 and keeps 17, so the estimate carries about a point of noise from the volatility input alone.

So what?

Use the measure as a screen rather than a probability. A leverage sort cannot see how stable the business underneath is; this one does, and the disagreement list is where the work sits. Oracle, Intel and Vistra rank among the riskiest 20 by distance to default and nowhere near it by leverage, because asset volatility does the ranking there.

For a covenant or counterparty screen, read both coordinates rather than the single number: a firm at 0.74 leverage and 17% asset volatility needs refinancing capacity, one at 0.11 leverage and 82% volatility needs its equity to stop moving. A point of estimation noise also argues against reacting to small moves: a name drifting from 8.6 to 7.9 has said nothing, while one going from 6 to 3 has repriced.

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

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