BLOG

Behind the numbers.

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

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 to Forecast Stock Volatility with GARCH Models in Python

What’s the question?

Historical volatility — the standard deviation of past returns — is backward-looking by definition. It tells you how much a stock moved, not how much it is likely to move tomorrow. For risk management, options pricing, and position sizing, the relevant quantity is forward-looking volatility. The question is whether past return behavior contains enough structure to forecast future volatility, and specifically whether volatility shocks persist (cluster) or dissipate quickly. A stock where a single large move predicts continued elevated volatility requires different risk management than one where shocks fade rapidly back to baseline.

The approach

The GARCH(1,1) model — Generalized Autoregressive Conditional Heteroskedasticity — is the standard parametric model for volatility forecasting. It decomposes the conditional variance (the variance of tomorrow’s return, given today’s information) into three components: a long-run baseline variance (omega), the impact of yesterday’s squared return shock (alpha), and the persistence of yesterday’s conditional variance (beta). The sum alpha + beta is called persistence: values near 1.0 mean volatility shocks decay slowly (strong clustering), while values well below 1.0 mean shocks dissipate quickly.

Four stocks with different volatility profiles are tested: Apple (AAPL), Nvidia (NVDA), ExxonMobil (XOM), and JPMorgan (JPM). One year of daily returns is fitted to a GARCH(1,1) specification using maximum likelihood estimation. The model then forecasts next-day volatility, which is compared against historical annualized volatility to classify the current regime as HIGH (forecast exceeds historical by 20%+), LOW (forecast is 20%+ below historical), or NORMAL.

import xfinlink as xfl
import pandas as pd
import numpy as np
from arch import arch_model

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

tickers = ["AAPL", "NVDA", "XOM", "JPM"]
df = xfl.prices(tickers, period="1y", fields=["close", "return_daily"])

for ticker in tickers:
    t = df[df["ticker"] == ticker].sort_values("date")
    returns = t["return_daily"].dropna() * 100  # scale to percent
    model = arch_model(returns, vol="Garch", p=1, q=1, dist="Normal", rescale=False)
    result = model.fit(disp="off")
    alpha, beta = result.params["alpha[1]"], result.params["beta[1]"]
    persistence = alpha + beta
    forecast = result.forecast(horizon=1)
    next_vol = np.sqrt(forecast.variance.iloc[-1, 0])
    ann_vol = next_vol * np.sqrt(252)
    hist_vol = returns.std() * np.sqrt(252)
    regime = "HIGH" if ann_vol > hist_vol * 1.2 else ("LOW" if ann_vol < hist_vol * 0.8 else "NORMAL")
    print(f"{ticker}: persistence={persistence:.4f} forecast={ann_vol:.1f}% hist={hist_vol:.1f}% regime={regime}")

Output:

=== GARCH(1,1) Volatility Forecast ===

  AAPL:
    GARCH params: omega=1.3003  alpha=0.0909  beta=0.2600  persistence=0.3509
    Forecast next-day vol: 1.38% daily = 22.0% annualized
    Historical vol:        22.5% annualized
    Regime: NORMAL

  NVDA:
    GARCH params: omega=1.9419  alpha=0.0875  beta=0.4749  persistence=0.5624
    Forecast next-day vol: 2.05% daily = 32.6% annualized
    Historical vol:        33.5% annualized
    Regime: NORMAL

  XOM:
    GARCH params: omega=0.0120  alpha=0.0305  beta=0.9682  persistence=0.9987
    Forecast next-day vol: 1.91% daily = 30.3% annualized
    Historical vol:        23.6% annualized
    Regime: HIGH

  JPM:
    GARCH params: omega=0.0083  alpha=0.0000  beta=0.9992  persistence=0.9992
    Forecast next-day vol: 1.61% daily = 25.6% annualized
    Historical vol:        21.1% annualized
    Regime: HIGH

What this tells us

The persistence parameter divides these four stocks into two distinct volatility regimes. AAPL (persistence = 0.35) and NVDA (persistence = 0.56) exhibit low to moderate persistence, meaning that after a volatility shock — a large daily move in either direction — the elevated volatility fades relatively quickly back toward its long-run level. Their forecast volatilities (22.0% and 32.6%) are close to their historical volatilities (22.5% and 33.5%), confirming that both stocks are currently in a normal volatility state.

XOM and JPM tell a fundamentally different story. Both have persistence values near 1.0 (0.999 for each), indicating extreme volatility clustering — once these stocks begin moving, the elevated volatility tends to self-perpetuate. The GARCH model reflects this by forecasting volatility substantially above the historical average: XOM’s forecast of 30.3% annualized exceeds its 23.6% historical vol by 28%, and JPM’s 25.6% forecast exceeds its 21.1% historical vol by 21%. Both are classified as HIGH regime.

The near-zero omega values for XOM (0.012) and JPM (0.008), combined with beta values near 1.0, mean that the long-run variance contributes almost nothing to the forecast. Tomorrow’s volatility is almost entirely determined by today’s volatility — a purely autoregressive process. In contrast, AAPL’s large omega (1.30) relative to its beta (0.26) means the long-run baseline dominates, producing mean-reverting volatility behavior.

So what?

For position sizing and risk management, the practical implication is direct. If you are using historical volatility to set position sizes or stop-loss levels, you are underestimating current risk for XOM and JPM by approximately 25–30%. The GARCH forecast provides a more accurate estimate of near-term risk because it incorporates the clustering effect. For AAPL and NVDA, historical volatility is an adequate proxy because their volatility mean-reverts quickly. The regime classification (NORMAL vs. HIGH) can serve as a simple signal: when a stock enters a HIGH volatility regime, reduce position size or widen stops to account for the persistence of elevated moves.

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