```python
import numpy as np
rng = np.random.default_rng(0)
ret = 1.2 * rng.normal(size=250)
r = vol_models(ret, 0.94, 0.05, 0.1, 0.85, 5)
print(([round(v, 4) for v in r['ewma'][-3:]], [round(v, 4) for v in r['garch'][-3:]], [round(v, 4) for v in r['forecast']], round(r['long_run_vol'], 4), round(r['nll'], 4)))
```
Both paths start at the mean squared return. The GARCH long-run variance is 0.05 / (1 - 0.1 - 0.85) = 1, a volatility of 1, so the multi-step forecasts move from tomorrow's estimate toward 1 at a rate set by the persistence 0.95.
A risk desk tracks how volatile an asset is today and how volatile it will be over the next few days. Compute the two standard recursive estimates, the RiskMetrics EWMA and GARCH(1,1), from a series of returns.
Implement vol_models(returns, lam, omega, alpha, beta, h) for returns r0,…,rn−1 (mean taken as zero). Both recursions start from v0=n1∑trt2:
EWMA: σ02=v0,σt+12=λσt2+(1−λ)rt2GARCH: s02=v0,st+12=ω+αrt2+βst2
for t=0,…,n−1. The last entry of each path is the forecast for the next, unseen return. Return a dict with:
ewma: list of σ02,…,σn2 (n+1 variances)
garch: list of s02,…,sn2 (n+1 variances)
forecast: list of h GARCH volatilities (square roots) for 1,…,h steps ahead, where the k-step variance is f1=sn2 and fk+1=ω+(α+β)fk
long_run_vol: ω/(1−α−β), or None when α+β≥1
nll: the Gaussian negative log-likelihood of the returns under the GARCH path, 21∑t=0n−1[ln(2πst2)+rt2/st2]
Notes
n≥1, the returns are not all zero, 0≤λ<1, ω>0, α,β≥0, h≥1.