Forum Sign in Register

Modeling and Forecasting Volatility in MATLAB: GARCH, EGARCH and the Econometrics Toolbox

Started by Support 5 days ago · 0 replies RSS

Modeling and Forecasting Volatility in MATLAB: GARCH, EGARCH and the Econometrics Toolbox

Most beginner strategies quietly assume that volatility is constant — a fixed stop distance, a fixed position size, a fixed "normal" daily range. Markets disagree. Volatility clusters: calm days follow calm days, and once a shock hits, large moves tend to bunch together for a while before things settle. If your risk model ignores that, it will size positions too large right when the market is most dangerous. This article shows how to model that behaviour in MATLAB using the Econometrics Toolbox, and how to turn a volatility forecast into something you can actually use.

Why GARCH?

GARCH — Generalized Autoregressive Conditional Heteroskedasticity — is the workhorse for this. The idea is simple even if the name isn't: today's variance is a mixture of a long-run average, yesterday's variance, and the size of yesterday's shock. That structure reproduces two things we see in real return series:

  • Volatility clustering — big moves are followed by big moves, quiet by quiet.
  • Mean reversion of variance — volatility is elevated after a shock but drifts back toward its long-run level.


A GARCH(1,1) is usually enough. Its conditional variance equation is:

variance(t) = Constant + ARCH * innovation(t-1)^2 + GARCH * variance(t-1)


The ARCH term is the reaction to the last shock; the GARCH term is the memory of past variance. Their sum is the persistence — how slowly volatility decays. Values near 1 (0.95–0.99 is typical for daily data) mean shocks fade slowly.

The MATLAB workflow

The Econometrics Toolbox represents a model as an object you create, estimate on data, and then infer or forecast with. Start from a price series and work on log returns:

% prices: column vector of daily closes
r = 100 * diff(log(prices)); % log returns, scaled to % for stable fitting

% GARCH(1,1) with a fitted mean (Offset) and Student-t innovations for fat tails
Mdl = garch('GARCHLags',1,'ARCHLags',1,'Offset',NaN,'Distribution','t');
EstMdl = estimate(Mdl, r); % maximum-likelihood fit
summarize(EstMdl); % parameter table, standard errors, logL/AIC

% Conditional (in-sample) volatility
v = infer(EstMdl, r); % conditional variances
condVol = sqrt(v); % daily conditional volatility

% Forecast variance 10 trading days ahead
vF = forecast(EstMdl, 10, 'Y0', r);
sigmaF = sqrt(vF); % forecast daily volatility
annualVol = sqrt(252) * sigmaF; % annualized


Scaling returns to percent and supplying 'Offset',NaN (so the model fits the small non-zero mean instead of assuming zero) both help the optimizer converge. The 'Distribution','t' option matters: financial returns have fatter tails than a normal distribution, and a Student-t innovation fits the extremes far better.

Leverage: when down-moves scare the market more

Plain GARCH treats a +3% and a −3% shock identically. In equity indices they are not identical — a sharp drop raises volatility more than an equal-sized rally. Two variants capture that asymmetry, and both are one-liners in MATLAB:

MdlE = egarch(1,1);   % EGARCH: models log-variance, allows asymmetry
MdlG = gjr(1,1); % GJR-GARCH: adds an extra term for negative shocks


Fit them the same way with estimate, then compare AIC/BIC from summarize against your GARCH(1,1). If the leverage term is significant and the information criteria improve, the asymmetric model is earning its extra parameter.

Turning a forecast into a decision

A volatility number is only useful if it changes what you do. Three common uses:

  • Volatility targeting. Scale position size inversely to forecast volatility so each trade risks a roughly constant amount: units = targetRisk / sigmaF. Positions shrink automatically when the market gets wild.
  • Adaptive stops. Set stop distance as a multiple of sigmaF instead of a fixed number of pips, so your stops breathe with the market.
  • Value at Risk. A one-day 99% VaR is roughly mu - z * sigmaF, where z comes from the fitted t-distribution's quantile — wider than the normal-based number precisely because of the fat tails.


Pitfalls to avoid

  • Too little data. GARCH needs a few hundred observations to estimate stably. A few weeks of data will give you confident-looking nonsense.
  • Ignoring the mean model. If returns are autocorrelated, model the mean (an ARIMA/offset) before the variance, or the GARCH picks up structure that isn't really volatility.
  • In-sample overconfidence. Judge the model on rolling, out-of-sample forecasts — re-estimate periodically and check the forecast against realized volatility, exactly as you would walk-forward test a strategy.
  • Forgetting persistence near 1. If ARCH + GARCH sums to essentially 1, the process is close to integrated (IGARCH) and long-horizon forecasts barely mean-revert — interpret them accordingly.


Bottom line

Volatility is one of the few things in markets that is genuinely predictable in the short run, and GARCH is a compact, well-understood way to capture it. In MATLAB the whole loop — create, estimate, infer, forecast — is a handful of lines, and the payoff is a risk model that tightens when the market is dangerous and relaxes when it is calm. That alone puts you ahead of any strategy still betting the same size every day.

This is educational content, not investment advice. Models are approximations; always validate out-of-sample and manage your risk.

Sign in to reply.