{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# ARCH and GARCH Models\n",
        "\n**Opening question:** How can returns be difficult to predict while their volatility remains persistent and forecastable?\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "\n",
        "rng = np.random.default_rng(40)\n",
        "omega, alpha, beta = 0.000002, 0.08, 0.88\n",
        "returns = np.zeros(750)\n",
        "variance = np.full(750, omega / (1 - alpha - beta))\n",
        "for t in range(1, len(returns)):\n",
        "    variance[t] = omega + alpha * returns[t - 1] ** 2 + beta * variance[t - 1]\n",
        "    returns[t] = np.sqrt(variance[t]) * rng.normal()\n",
        "\n",
        "print(\"Simulated observations:\", len(returns))\n",
        "print(\"Annualized volatility:\", round(float(returns.std() * np.sqrt(252)), 3))\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The custom estimator is included for transparency and teaching. Production work should compare a maintained package and verify parameterization.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "\n",
        "daily_sigma = np.array([0.008, 0.012, 0.010])\n",
        "annualized = daily_sigma * np.sqrt(252)\n",
        "print(np.round(annualized, 3))\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**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.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Verified source output\n",
        "\n",
        "```text\n0.94347 True\n```\n\n```text\n[0.127 0.19 0.159]\n```\n\n```text\n[0.127 0.19  0.159]\n```\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3"
    },
    "ceteris_lab": {
      "course_slug": "fundamentals-python-econometrics",
      "source_derived": true,
      "course_title": "Fundamentals of Python for Financial Econometrics",
      "chapter": 40,
      "source_origin": "source-derived"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
