{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b9671c6a",
   "metadata": {},
   "source": [
    "# DCT Laboratory — Volume I, Chapter 10\n",
    "## Enterprise Capital Architecture\n",
    "**Seed `26110`** · Companion to the chapter and AXIOM Module **AXIOM-10**\n",
    "\n",
    "Capital beyond finance, in motion: three stocks (Financial, Human, Technological)\n",
    "under the accumulation law $K_{k+1} = (1-\\delta)K_k + I_k$, two allocation\n",
    "policies through a multiplicative productivity function, and the\n",
    "**accumulation/depletion asymmetry** — destroyed in one quarter, rebuilt in ten.\n",
    "Mirrored in `DCT_V1_Ch10_Lab.xlsx`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d61190db",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-13T22:53:04.798936Z",
     "iopub.status.busy": "2026-07-13T22:53:04.798720Z",
     "iopub.status.idle": "2026-07-13T22:53:05.331635Z",
     "shell.execute_reply": "2026-07-13T22:53:05.330385Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams['figure.dpi']=110\n",
    "\n",
    "import numpy as np\n",
    "SEED = 26110\n",
    "K0    = np.array([40.0, 30.0, 20.0])          # Financial, Human, Technological\n",
    "DELTA = np.array([0.02, 0.06, 0.10])\n",
    "ALPHA = np.array([0.30, 0.40, 0.30])\n",
    "A_TFP, N = 10.0, 20\n",
    "I_A = np.array([2.0, 2.0, 2.0])               # balanced allocation\n",
    "I_B = np.array([4.0, 1.0, 1.0])               # finance-heavy allocation\n",
    "\n",
    "def path(I, n=N, k0=K0, shock=None):\n",
    "    \"\"\"shock = (quarter, index, multiplier) applied AFTER accumulation that quarter.\"\"\"\n",
    "    ks = np.empty((n+1, 3)); ks[0] = k0\n",
    "    for k in range(n):\n",
    "        ks[k+1] = (1-DELTA)*ks[k] + I\n",
    "        if shock and k+1 == shock[0]:\n",
    "            ks[k+1, shock[1]] *= shock[2]\n",
    "    return ks\n",
    "\n",
    "def output(ks):\n",
    "    return A_TFP*np.prod(ks**ALPHA, axis=1)\n",
    "\n",
    "def recovery_quarters():\n",
    "    base = path(I_A)\n",
    "    pre = base[10, 1]                          # Human capital before the shock\n",
    "    sh = path(I_A, shock=(10, 1, 0.7))\n",
    "    later = sh[11:, 1]\n",
    "    below = int((later < pre).sum())           # quarters spent below pre-shock level\n",
    "    return pre, below\n",
    "\n",
    "def reference_values():\n",
    "    ka, kb = path(I_A), path(I_B)\n",
    "    ya, yb = output(ka), output(kb)\n",
    "    pre, rec = recovery_quarters()\n",
    "    return {\n",
    "        \"F20_A\": round(float(ka[20,0]),4), \"H20_A\": round(float(ka[20,1]),4),\n",
    "        \"T20_A\": round(float(ka[20,2]),4),\n",
    "        \"Y20_A\": round(float(ya[20]),4), \"Y20_B\": round(float(yb[20]),4),\n",
    "        \"cumY_gap_A_minus_B\": round(float(ya[1:].sum()-yb[1:].sum()),4),\n",
    "        \"H10_preshock\": round(float(pre),4),\n",
    "        \"recovery_quarters\": rec,\n",
    "    }\n",
    "if __name__ == \"__main__\":\n",
    "    [print(f\"{k:22s} {v}\") for k,v in reference_values().items()]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41a55a0b",
   "metadata": {},
   "source": [
    "## Panel 1 — Two allocations of the same budget\n",
    "Six units of investment per quarter, split balanced (2,2,2) vs finance-heavy\n",
    "(4,1,1). Financial capital depreciates slowest — and the finance-heavy policy\n",
    "still loses: output is multiplicative in the stocks (Capital Productivity\n",
    "Theorem), so starving the fast-depreciating stocks costs more than stacking the\n",
    "durable one earns. Cumulative gap over five years: **800 output units**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50435b4a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-13T22:53:05.333690Z",
     "iopub.status.busy": "2026-07-13T22:53:05.333413Z",
     "iopub.status.idle": "2026-07-13T22:53:05.699739Z",
     "shell.execute_reply": "2026-07-13T22:53:05.698623Z"
    }
   },
   "outputs": [],
   "source": [
    "ka, kb = path(I_A), path(I_B)\n",
    "ya, yb = output(ka), output(kb)\n",
    "t = np.arange(N+1)/4\n",
    "fig, axes = plt.subplots(1, 2, figsize=(10,4.1))\n",
    "for i,(nm,c) in enumerate(zip([\"Financial\",\"Human\",\"Technological\"],[\"#0B3D2E\",\"#C8A24B\",\"#1B6B52\"])):\n",
    "    axes[0].plot(t, ka[:,i], c=c, lw=2.2, label=nm+\" (balanced)\")\n",
    "    axes[0].plot(t, kb[:,i], c=c, lw=1.6, ls=\"--\")\n",
    "axes[0].set(xlabel=\"years\", ylabel=\"stock\", title=\"Stocks: solid = balanced, dashed = finance-heavy\")\n",
    "axes[0].legend(frameon=False, fontsize=9); axes[0].grid(alpha=.25)\n",
    "axes[1].plot(t, ya, c=\"#C8A24B\", lw=2.4, label=f\"balanced → Y₂₀ = {ya[20]:.1f}\")\n",
    "axes[1].plot(t, yb, c=\"#8A8F8B\", lw=2.2, ls=\"--\", label=f\"finance-heavy → Y₂₀ = {yb[20]:.1f}\")\n",
    "axes[1].set(xlabel=\"years\", ylabel=\"output Y\", title=\"Productivity: Y = A·F^0.3 H^0.4 T^0.3\")\n",
    "axes[1].legend(frameon=False, fontsize=9); axes[1].grid(alpha=.25)\n",
    "plt.tight_layout(); plt.show()\n",
    "print(f\"cumulative output gap (balanced − finance-heavy): {ya[1:].sum()-yb[1:].sum():.4f}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b1511f8",
   "metadata": {},
   "source": [
    "## Panel 2 — The asymmetry: one quarter down, ten quarters back\n",
    "A 30% human-capital destruction at quarter 10 (a botched reorganization, a\n",
    "talent exodus). Under unchanged investment, the stock needs **10 quarters** to\n",
    "regain its pre-shock level — Depletion Reduces Adaptability, Asymmetrically\n",
    "(Prop.), measured rather than asserted."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5262474c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-13T22:53:05.702357Z",
     "iopub.status.busy": "2026-07-13T22:53:05.701611Z",
     "iopub.status.idle": "2026-07-13T22:53:05.887798Z",
     "shell.execute_reply": "2026-07-13T22:53:05.885604Z"
    }
   },
   "outputs": [],
   "source": [
    "base = path(I_A); sh = path(I_A, shock=(10,1,0.7))\n",
    "pre, rec = recovery_quarters()\n",
    "fig, ax = plt.subplots(figsize=(8.2,4.2))\n",
    "ax.plot(t, base[:,1], c=\"#8A8F8B\", lw=2, ls=\"--\", label=\"no shock\")\n",
    "ax.plot(t, sh[:,1], c=\"#C8A24B\", lw=2.4, label=\"30% destruction at q10\")\n",
    "ax.axhline(pre, c=\"#0B3D2E\", lw=1, ls=\":\", label=f\"pre-shock level {pre:.2f}\")\n",
    "ax.axvspan(2.5, 2.5+rec/4, color=\"#B0532F\", alpha=.08)\n",
    "ax.set(xlabel=\"years\", ylabel=\"Human capital H\", title=f\"Recovery takes {rec} quarters (seed 26110)\")\n",
    "ax.legend(frameon=False); ax.grid(alpha=.25); plt.tight_layout(); plt.show()\n",
    "print(f\"pre-shock H at q10: {pre:.4f}   quarters below pre-shock after destruction: {rec}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d0aa480",
   "metadata": {},
   "source": [
    "## Panel 3 — Capital dependency, one edge\n",
    "Human-capital investment is funded from financial capital: raise $I_H$ and $I_F$\n",
    "falls by the same amount. The Capital Dependency Theorem in a one-line sweep —\n",
    "each capital's best level is not independent of the others'."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f82a4157",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-13T22:53:05.890094Z",
     "iopub.status.busy": "2026-07-13T22:53:05.889873Z",
     "iopub.status.idle": "2026-07-13T22:53:05.896629Z",
     "shell.execute_reply": "2026-07-13T22:53:05.895410Z"
    }
   },
   "outputs": [],
   "source": [
    "print(f\"{'I_H':>5s} {'I_F':>5s} {'Y at q20':>10s}\")\n",
    "for ih in [1.0, 2.0, 3.0, 4.0]:\n",
    "    I = np.array([6.0-ih-1.0, ih, 1.0])\n",
    "    y = output(path(I))[20]\n",
    "    print(f\"{ih:5.1f} {6.0-ih-1.0:5.1f} {y:10.4f}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f813a39",
   "metadata": {},
   "source": [
    "## Validation — agrees with `DCT_V1_Ch10_Lab.xlsx`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "04acb6e9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-13T22:53:05.899173Z",
     "iopub.status.busy": "2026-07-13T22:53:05.898436Z",
     "iopub.status.idle": "2026-07-13T22:53:05.905568Z",
     "shell.execute_reply": "2026-07-13T22:53:05.904418Z"
    }
   },
   "outputs": [],
   "source": [
    "ref = reference_values()\n",
    "expected = {\"F20_A\":59.9435,\"H20_A\":32.3663,\"T20_A\":20.0,\"Y20_A\":337.0303,\"Y20_B\":269.6156,\n",
    " \"cumY_gap_A_minus_B\":800.4275,\"H10_preshock\":31.5379,\"recovery_quarters\":10}\n",
    "for k,v in expected.items():\n",
    "    assert abs(ref[k]-v)<5e-4, f\"MISMATCH {k}\"\n",
    "    print(f\"PASS  {k:22s} {ref[k]}\")\n",
    "print(\"\\nAll checkpoints agree — seed 26110.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee28c206",
   "metadata": {},
   "source": [
    "**Next**: Exercises 10.9–10.12 (Part C) sweep δ, α, and the shock size; AXIOM-10's allocation bench makes the budget split draggable. Solutions: IM Ch. 10."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
