{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Introduction to Time-Series Data\n",
        "\n**Opening question:** What changes when observations are ordered in time and yesterday can influence today?\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "\n",
        "prices = pd.Series([100, 102, 101, 104], index=pd.date_range(\"2026-01-01\", periods=4, freq=\"D\"))\n",
        "simple = prices.pct_change()\n",
        "log_return = np.log(prices).diff()\n",
        "print(simple.dropna().round(4).tolist())\n",
        "print(log_return.dropna().round(4).tolist())\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The two measures are close for small changes but are not numerically identical.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import pandas as pd\n",
        "\n",
        "idx = pd.date_range(\"2026-01-01\", periods=60, freq=\"D\")\n",
        "daily = pd.DataFrame({\"rate\": range(60), \"volume\": [100]*60}, index=idx)\n",
        "monthly = daily.resample(\"ME\").agg(rate=(\"rate\", \"last\"), volume=(\"volume\", \"sum\"))\n",
        "print(monthly)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The rate uses the last observation while volume is summed, reflecting different measurement concepts.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "simple = prices.pct_change()\n",
        "log_return = np.log(prices).diff()\n",
        "print(simple.dropna().round(4).tolist())\n",
        "print(log_return.dropna().round(4).tolist())\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Verified source output\n",
        "\n",
        "```text\n[0.02, -0.0098, 0.0297] [0.0198, -0.0099, 0.0293]\n```\n\n```text\nrate volume 2026-01-31 30 3100 2026-02-28 58 2800 2026-03-31 59 100\n```\n\n```text\n[0.02, -0.0098, 0.0297]\n[0.0198, -0.0099, 0.0293]\n```\n\n```text\nrate  volume\n2026-01-31    30    3100\n2026-02-28    58    2800\n2026-03-31    59     100\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": 36,
      "source_origin": "source-derived"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
