{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Obtaining Economic and Financial Data\n",
        "\n**Opening question:** How can a live data source be used without making the analysis disappear when the network or provider changes?\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "from io import StringIO\n",
        "import pandas as pd\n",
        "\n",
        "frozen_csv = StringIO(\"\"\"date,FXUSDCAD\n",
        "2024-04-15,1.3762\n",
        "2024-04-16,1.3778\n",
        "2024-04-17,1.3731\n",
        "2024-04-18,1.3704\n",
        "2024-04-19,1.3746\n",
        "\"\"\")\n",
        "fx = pd.read_csv(frozen_csv, parse_dates=[\"date\"])\n",
        "print(fx.shape[0], round(fx[\"FXUSDCAD\"].mean(), 4))\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The frozen file makes the example independent of a live request while preserving the official series identifier.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "source_url = \"https://www.bankofcanada.ca/valet/observations/FXUSDCAD/json\"\n",
        "print(\"Official Bank of Canada endpoint:\", source_url)\n",
        "print(\"This browser lab uses the frozen five-observation sample above for reproducibility.\")\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The timeout and exception handling prevent an indefinite hang. Production code should also validate schema and use the frozen fallback.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Verified source output\n",
        "\n",
        "```text\n23 1.3708\n```\n\n```text\n5\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": 16,
      "source_origin": "source-derived"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
