# Chapter 40: ARCH and GARCH Models
# Fundamentals of Python for Financial Econometrics - ARCH and GARCH Models
# Dataset: Ceteris Lab teaching sample

# ARCH and GARCH Models
#
# **Opening question:** How can returns be difficult to predict while their volatility remains persistent and forecastable?

# %% Cell 2
import numpy as np

rng = np.random.default_rng(40)
omega, alpha, beta = 0.000002, 0.08, 0.88
returns = np.zeros(750)
variance = np.full(750, omega / (1 - alpha - beta))
for t in range(1, len(returns)):
    variance[t] = omega + alpha * returns[t - 1] ** 2 + beta * variance[t - 1]
    returns[t] = np.sqrt(variance[t]) * rng.normal()

print("Simulated observations:", len(returns))
print("Annualized volatility:", round(float(returns.std() * np.sqrt(252)), 3))

# **Interpretation check:** Interpretation. The custom estimator is included for transparency and teaching. Production work should compare a maintained package and verify parameterization.

# %% Cell 4
import numpy as np

daily_sigma = np.array([0.008, 0.012, 0.010])
annualized = daily_sigma * np.sqrt(252)
print(np.round(annualized, 3))

# **Interpretation check:** Interpretation. Square-root-of-time annualization assumes a daily variance scale and should not be applied blindly when dependence or horizon dynamics matter.

# Verified source output
#
# ```text
# 0.94347 True
# ```
#
# ```text
# [0.127 0.19 0.159]
# ```
#
# ```text
# [0.127 0.19  0.159]
# ```
