{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Stochastic Processes and Option Pricing\n",
        "\n**Opening question:** How can continuous-time uncertainty be simulated and translated into a no-arbitrage option value?\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "\n",
        "rng = np.random.default_rng(24)\n",
        "S0, mu, sigma, T, steps = 100, 0.06, 0.20, 1, 252\n",
        "dt = T / steps\n",
        "z = rng.normal(size=steps)\n",
        "log_path = np.log(S0) + np.cumsum((mu - 0.5 * sigma**2) * dt + sigma * np.sqrt(dt) * z)\n",
        "print(round(float(np.exp(log_path[-1])), 2))\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. One path is a possible model realization, not a forecast. Many paths are needed for a distribution or Monte Carlo estimate.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "from math import erf, exp, log, sqrt\n",
        "\n",
        "def normal_cdf(value):\n",
        "    return 0.5 * (1 + erf(value / sqrt(2)))\n",
        "\n",
        "def black_scholes_call(S, K, T, r, sigma):\n",
        "    d1 = (log(S / K) + (r + 0.5 * sigma**2) * T) / (sigma * sqrt(T))\n",
        "    d2 = d1 - sigma * sqrt(T)\n",
        "    return S * normal_cdf(d1) - K * exp(-r * T) * normal_cdf(d2)\n",
        "\n",
        "price = black_scholes_call(S=100, K=100, T=1, r=0.03, sigma=0.20)\n",
        "print(round(price, 4))\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The value is conditional on the model inputs and assumptions. It is not a trading recommendation or a guarantee of market price.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Verified source output\n",
        "\n",
        "```text\n59.88\n```\n\n```text\n9.4134\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": 43,
      "source_origin": "source-derived"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
