{ "cells": [ { "cell_type": "markdown", "id": "9556e242", "metadata": {}, "source": [ "\n", "" ] }, { "cell_type": "markdown", "id": "312a8006", "metadata": {}, "source": [ "# Uncertainty Traps" ] }, { "cell_type": "markdown", "id": "edb1ac8b", "metadata": {}, "source": [ "## Contents\n", "\n", "- [Uncertainty Traps](#Uncertainty-Traps) \n", " - [Overview](#Overview) \n", " - [The Model](#The-Model) \n", " - [Implementation](#Implementation) \n", " - [Results](#Results) \n", " - [Exercises](#Exercises) " ] }, { "cell_type": "markdown", "id": "ee063a92", "metadata": {}, "source": [ "## Overview\n", "\n", "In this lecture, we study a simplified version of an uncertainty traps model of Fajgelbaum, Schaal and Taschereau-Dumouchel [[Fajgelbaum *et al.*, 2015](https://python.quantecon.org/zreferences.html#id136)].\n", "\n", "The model features self-reinforcing uncertainty that has big impacts on economic activity.\n", "\n", "In the model,\n", "\n", "- Fundamentals vary stochastically and are not fully observable. \n", "- At any moment there are both active and inactive entrepreneurs; only active entrepreneurs produce. \n", "- Agents – active and inactive entrepreneurs – have beliefs about the fundamentals expressed as probability distributions. \n", "- Greater uncertainty means greater dispersions of these distributions. \n", "- Entrepreneurs are risk-averse and hence less inclined to be active when uncertainty is high. \n", "- The output of active entrepreneurs is observable, supplying a noisy signal that helps everyone inside the model infer fundamentals. \n", "- Entrepreneurs update their beliefs about fundamentals using Bayes’ Law, implemented via [Kalman filtering](https://python.quantecon.org/kalman.html). \n", "\n", "\n", "Uncertainty traps emerge because:\n", "\n", "- High uncertainty discourages entrepreneurs from becoming active. \n", "- A low level of participation – i.e., a smaller number of active entrepreneurs – diminishes the flow of information about fundamentals. \n", "- Less information translates to higher uncertainty, further discouraging entrepreneurs from choosing to be active, and so on. \n", "\n", "\n", "Uncertainty traps stem from a positive externality: high aggregate economic activity levels generates valuable information.\n", "\n", "Let’s start with some standard imports:" ] }, { "cell_type": "code", "execution_count": null, "id": "5e6d66a6", "metadata": { "hide-output": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "plt.rcParams[\"figure.figsize\"] = (11, 5) #set default figure size\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "000a6002", "metadata": {}, "source": [ "## The Model\n", "\n", "The original model described in [[Fajgelbaum *et al.*, 2015](https://python.quantecon.org/zreferences.html#id136)] has many interesting moving parts.\n", "\n", "Here we examine a simplified version that nonetheless captures many of the key ideas." ] }, { "cell_type": "markdown", "id": "c4000066", "metadata": {}, "source": [ "### Fundamentals\n", "\n", "The evolution of the fundamental process $ \\{\\theta_t\\} $ is given by\n", "\n", "$$\n", "\\theta_{t+1} = \\rho \\theta_t + \\sigma_{\\theta} w_{t+1}\n", "$$\n", "\n", "where\n", "\n", "- $ \\sigma_\\theta > 0 $ and $ 0 < \\rho < 1 $ \n", "- $ \\{w_t\\} $ is IID and standard normal \n", "\n", "\n", "The random variable $ \\theta_t $ is not observable at any time." ] }, { "cell_type": "markdown", "id": "23eb293b", "metadata": {}, "source": [ "### Output\n", "\n", "There is a total $ \\bar M $ of risk-averse entrepreneurs.\n", "\n", "Output of the $ m $-th entrepreneur, conditional on being active in the market at\n", "time $ t $, is equal to\n", "\n", "\n", "\n", "$$\n", "x_m = \\theta + \\epsilon_m\n", "\\quad \\text{where} \\quad\n", "\\epsilon_m \\sim N \\left(0, \\gamma_x^{-1} \\right) \\tag{65.1}\n", "$$\n", "\n", "Here the time subscript has been dropped to simplify notation.\n", "\n", "The inverse of the shock variance, $ \\gamma_x $, is called the shock’s **precision**.\n", "\n", "The higher is the precision, the more informative $ x_m $ is about the fundamental.\n", "\n", "Output shocks are independent across time and firms." ] }, { "cell_type": "markdown", "id": "4da4f385", "metadata": {}, "source": [ "### Information and Beliefs\n", "\n", "All entrepreneurs start with identical beliefs about $ \\theta_0 $.\n", "\n", "Signals are publicly observable and hence all agents have identical beliefs always.\n", "\n", "Dropping time subscripts, beliefs for current $ \\theta $ are represented by the normal\n", "distribution $ N(\\mu, \\gamma^{-1}) $.\n", "\n", "Here $ \\gamma $ is the precision of beliefs; its inverse is the degree of uncertainty.\n", "\n", "These parameters are updated by Kalman filtering.\n", "\n", "Let\n", "\n", "- $ \\mathbb M \\subset \\{1, \\ldots, \\bar M\\} $ denote the set of currently active firms. \n", "- $ M := |\\mathbb M| $ denote the number of currently active firms. \n", "- $ X $ be the average output $ \\frac{1}{M} \\sum_{m \\in \\mathbb M} x_m $ of the active firms. \n", "\n", "\n", "With this notation and primes for next period values, we can write the updating of the mean and precision via\n", "\n", "\n", "\n", "$$\n", "\\mu' = \\rho \\frac{\\gamma \\mu + M \\gamma_x X}{\\gamma + M \\gamma_x} \\tag{65.2}\n", "$$\n", "\n", "\n", "\n", "$$\n", "\\gamma' =\n", " \\left(\n", " \\frac{\\rho^2}{\\gamma + M \\gamma_x} + \\sigma_\\theta^2\n", " \\right)^{-1} \\tag{65.3}\n", "$$\n", "\n", "These are standard Kalman filtering results applied to the current setting.\n", "\n", "Exercise 1 provides more details on how [(65.2)](#equation-update-mean) and [(65.3)](#equation-update-prec) are derived and then asks you to fill in remaining steps.\n", "\n", "The next figure plots the law of motion for the precision in [(65.3)](#equation-update-prec)\n", "as a 45 degree diagram, with one curve for each $ M \\in \\{0, \\ldots, 6\\} $.\n", "\n", "The other parameter values are $ \\rho = 0.99, \\gamma_x = 0.5, \\sigma_\\theta =0.5 $\n", "\n", "![https://python.quantecon.org/_static/lecture_specific/uncertainty_traps/uncertainty_traps_45.png](https://python.quantecon.org/_static/lecture_specific/uncertainty_traps/uncertainty_traps_45.png)\n", "\n", " \n", "Points where the curves hit the 45 degree lines are long-run steady\n", "states for precision for different values of $ M $.\n", "\n", "Thus, if one of these values for $ M $ remains fixed, a corresponding steady state is the equilibrium level of precision\n", "\n", "- high values of $ M $ correspond to greater information about the\n", " fundamental, and hence more precision in steady state \n", "- low values of $ M $ correspond to less information and more uncertainty in steady state \n", "\n", "\n", "In practice, as we’ll see, the number of active firms fluctuates stochastically." ] }, { "cell_type": "markdown", "id": "099704ca", "metadata": {}, "source": [ "### Participation\n", "\n", "Omitting time subscripts once more, entrepreneurs enter the market in the current period if\n", "\n", "\n", "\n", "$$\n", "\\mathbb E [ u(x_m - F_m) ] > c \\tag{65.4}\n", "$$\n", "\n", "Here\n", "\n", "- the mathematical expectation of $ x_m $ is based on [(65.1)](#equation-xgt) and beliefs $ N(\\mu, \\gamma^{-1}) $ for $ \\theta $ \n", "- $ F_m $ is a stochastic but pre-visible fixed cost, independent across time and firms \n", "- $ c $ is a constant reflecting opportunity costs \n", "\n", "\n", "The statement that $ F_m $ is pre-visible means that it is realized at the start of the period and treated as a constant in [(65.4)](#equation-pref1).\n", "\n", "The utility function has the constant absolute risk aversion form\n", "\n", "\n", "\n", "$$\n", "u(x) = \\frac{1}{a} \\left(1 - \\exp(-a x) \\right) \\tag{65.5}\n", "$$\n", "\n", "where $ a $ is a positive parameter.\n", "\n", "Combining [(65.4)](#equation-pref1) and [(65.5)](#equation-pref2), entrepreneur $ m $ participates in the market (or is said to be active) when\n", "\n", "$$\n", "\\frac{1}{a}\n", " \\left\\{\n", " 1 - \\mathbb E [ \\exp \\left(\n", " -a (\\theta + \\epsilon_m - F_m)\n", " \\right) ]\n", " \\right\\}\n", " > c\n", "$$\n", "\n", "Using standard formulas for expectations of [lognormal](https://en.wikipedia.org/wiki/Log-normal_distribution) random variables, this is equivalent to the condition\n", "\n", "\n", "\n", "$$\n", "\\psi(\\mu, \\gamma, F_m) :=\n", "\\frac{1}{a}\n", " \\left(\n", " 1 - \\exp \\left(\n", " -a \\mu + a F_m +\n", " \\frac{a^2 \\left( \\frac{1}{\\gamma} + \\frac{1}{\\gamma_x} \\right)}{2}\n", " \\right)\n", " \\right) - c > 0 \\tag{65.6}\n", "$$" ] }, { "cell_type": "markdown", "id": "d2623f91", "metadata": {}, "source": [ "## Implementation\n", "\n", "We want to simulate this economy.\n", "\n", "As a first step, let’s put together a class that bundles\n", "\n", "- the parameters, the current value of $ \\theta $ and the current values of the\n", " two belief parameters $ \\mu $ and $ \\gamma $ \n", "- methods to update $ \\theta $, $ \\mu $ and $ \\gamma $, as well as to determine the number of active firms and their outputs \n", "\n", "\n", "The updating methods follow the laws of motion for $ \\theta $, $ \\mu $ and $ \\gamma $ given above.\n", "\n", "The method to evaluate the number of active firms generates $ F_1,\n", "\\ldots, F_{\\bar M} $ and tests condition [(65.6)](#equation-firm-test) for each firm.\n", "\n", "The **init** method encodes as default values the parameters we’ll use in the simulations below" ] }, { "cell_type": "code", "execution_count": null, "id": "47e4e7b0", "metadata": { "hide-output": false }, "outputs": [], "source": [ "class UncertaintyTrapEcon:\n", "\n", " def __init__(self,\n", " a=1.5, # Risk aversion\n", " γ_x=0.5, # Production shock precision\n", " ρ=0.99, # Correlation coefficient for θ\n", " σ_θ=0.5, # Standard dev of θ shock\n", " num_firms=100, # Number of firms\n", " σ_F=1.5, # Standard dev of fixed costs\n", " c=-420, # External opportunity cost\n", " μ_init=0, # Initial value for μ\n", " γ_init=4, # Initial value for γ\n", " θ_init=0): # Initial value for θ\n", "\n", " # == Record values == #\n", " self.a, self.γ_x, self.ρ, self.σ_θ = a, γ_x, ρ, σ_θ\n", " self.num_firms, self.σ_F, self.c, = num_firms, σ_F, c\n", " self.σ_x = np.sqrt(1/γ_x)\n", "\n", " # == Initialize states == #\n", " self.γ, self.μ, self.θ = γ_init, μ_init, θ_init\n", "\n", " def ψ(self, F):\n", " temp1 = -self.a * (self.μ - F)\n", " temp2 = self.a**2 * (1/self.γ + 1/self.γ_x) / 2\n", " return (1 / self.a) * (1 - np.exp(temp1 + temp2)) - self.c\n", "\n", " def update_beliefs(self, X, M):\n", " \"\"\"\n", " Update beliefs (μ, γ) based on aggregates X and M.\n", " \"\"\"\n", " # Simplify names\n", " γ_x, ρ, σ_θ = self.γ_x, self.ρ, self.σ_θ\n", " # Update μ\n", " temp1 = ρ * (self.γ * self.μ + M * γ_x * X)\n", " temp2 = self.γ + M * γ_x\n", " self.μ = temp1 / temp2\n", " # Update γ\n", " self.γ = 1 / (ρ**2 / (self.γ + M * γ_x) + σ_θ**2)\n", "\n", " def update_θ(self, w):\n", " \"\"\"\n", " Update the fundamental state θ given shock w.\n", " \"\"\"\n", " self.θ = self.ρ * self.θ + self.σ_θ * w\n", "\n", " def gen_aggregates(self):\n", " \"\"\"\n", " Generate aggregates based on current beliefs (μ, γ). This\n", " is a simulation step that depends on the draws for F.\n", " \"\"\"\n", " F_vals = self.σ_F * np.random.randn(self.num_firms)\n", " M = np.sum(self.ψ(F_vals) > 0) # Counts number of active firms\n", " if M > 0:\n", " x_vals = self.θ + self.σ_x * np.random.randn(M)\n", " X = x_vals.mean()\n", " else:\n", " X = 0\n", " return X, M" ] }, { "cell_type": "markdown", "id": "59b0c05d", "metadata": {}, "source": [ "In the results below we use this code to simulate time series for the major variables." ] }, { "cell_type": "markdown", "id": "fcbadecd", "metadata": {}, "source": [ "## Results\n", "\n", "Let’s look first at the dynamics of $ \\mu $, which the agents use to track $ \\theta $\n", "\n", "![https://python.quantecon.org/_static/lecture_specific/uncertainty_traps/uncertainty_traps_mu.png](https://python.quantecon.org/_static/lecture_specific/uncertainty_traps/uncertainty_traps_mu.png)\n", "\n", " \n", "We see that $ \\mu $ tracks $ \\theta $ well when there are sufficient firms in the market.\n", "\n", "However, there are times when $ \\mu $ tracks $ \\theta $ poorly due to\n", "insufficient information.\n", "\n", "These are episodes where the uncertainty traps take hold.\n", "\n", "During these episodes\n", "\n", "- precision is low and uncertainty is high \n", "- few firms are in the market \n", "\n", "\n", "To get a clearer idea of the dynamics, let’s look at all the main time series\n", "at once, for a given set of shocks\n", "\n", "![https://python.quantecon.org/_static/lecture_specific/uncertainty_traps/uncertainty_traps_sim.png](https://python.quantecon.org/_static/lecture_specific/uncertainty_traps/uncertainty_traps_sim.png)\n", "\n", " \n", "Notice how the traps only take hold after a sequence of bad draws for the fundamental.\n", "\n", "Thus, the model gives us a *propagation mechanism* that maps bad random draws into long downturns in economic activity." ] }, { "cell_type": "markdown", "id": "779cb16c", "metadata": {}, "source": [ "## Exercises" ] }, { "cell_type": "markdown", "id": "d11eddaf", "metadata": {}, "source": [ "## Exercise 65.1\n", "\n", "Fill in the details behind [(65.2)](#equation-update-mean) and [(65.3)](#equation-update-prec) based on\n", "the following standard result (see, e.g., p. 24 of [[Young and Smith, 2005](https://python.quantecon.org/zreferences.html#id137)]).\n", "\n", "**Fact** Let $ \\mathbf x = (x_1, \\ldots, x_M) $ be a vector of IID draws\n", "from common distribution $ N(\\theta, 1/\\gamma_x) $\n", "and let $ \\bar x $ be the sample mean. If $ \\gamma_x $\n", "is known and the prior for $ \\theta $ is $ N(\\mu, 1/\\gamma) $, then the posterior\n", "distribution of $ \\theta $ given $ \\mathbf x $ is\n", "\n", "$$\n", "\\pi(\\theta \\,|\\, \\mathbf x) = N(\\mu_0, 1/\\gamma_0)\n", "$$\n", "\n", "where\n", "\n", "$$\n", "\\mu_0 = \\frac{\\mu \\gamma + M \\bar x \\gamma_x}{\\gamma + M \\gamma_x}\n", "\\quad \\text{and} \\quad\n", "\\gamma_0 = \\gamma + M \\gamma_x\n", "$$" ] }, { "cell_type": "markdown", "id": "123743b3", "metadata": {}, "source": [ "## Solution to[ Exercise 65.1](https://python.quantecon.org/#uncertainty_traps_ex1)\n", "\n", "This exercise asked you to validate the laws of motion for\n", "$ \\gamma $ and $ \\mu $ given in the lecture, based on the stated\n", "result about Bayesian updating in a scalar Gaussian setting. The stated\n", "result tells us that after observing average output $ X $ of the\n", "$ M $ firms, our posterior beliefs will be\n", "\n", "$$\n", "N(\\mu_0, 1/\\gamma_0)\n", "$$\n", "\n", "where\n", "\n", "$$\n", "\\mu_0 = \\frac{\\mu \\gamma + M X \\gamma_x}{\\gamma + M \\gamma_x}\n", "\\quad \\text{and} \\quad\n", "\\gamma_0 = \\gamma + M \\gamma_x\n", "$$\n", "\n", "If we take a random variable $ \\theta $ with this distribution and\n", "then evaluate the distribution of $ \\rho \\theta + \\sigma_\\theta w $\n", "where $ w $ is independent and standard normal, we get the\n", "expressions for $ \\mu' $ and $ \\gamma' $ given in the lecture." ] }, { "cell_type": "markdown", "id": "03b90655", "metadata": {}, "source": [ "## Exercise 65.2\n", "\n", "Modulo randomness, replicate the simulation figures shown above.\n", "\n", "- Use the parameter values listed as defaults in the **init** method of the UncertaintyTrapEcon class. " ] }, { "cell_type": "markdown", "id": "bd224075", "metadata": {}, "source": [ "## Solution to[ Exercise 65.2](https://python.quantecon.org/#uncertainty_traps_ex2)\n", "\n", "First, let’s replicate the plot that illustrates the law of motion for\n", "precision, which is\n", "\n", "$$\n", "\\gamma_{t+1} =\n", " \\left(\n", " \\frac{\\rho^2}{\\gamma_t + M \\gamma_x} + \\sigma_\\theta^2\n", " \\right)^{-1}\n", "$$\n", "\n", "Here $ M $ is the number of active firms. The next figure plots\n", "$ \\gamma_{t+1} $ against $ \\gamma_t $ on a 45 degree diagram for\n", "different values of $ M $" ] }, { "cell_type": "code", "execution_count": null, "id": "3cba948b", "metadata": { "hide-output": false }, "outputs": [], "source": [ "econ = UncertaintyTrapEcon()\n", "ρ, σ_θ, γ_x = econ.ρ, econ.σ_θ, econ.γ_x # Simplify names\n", "γ = np.linspace(1e-10, 3, 200) # γ grid\n", "fig, ax = plt.subplots(figsize=(9, 9))\n", "ax.plot(γ, γ, 'k-') # 45 degree line\n", "\n", "for M in range(7):\n", " γ_next = 1 / (ρ**2 / (γ + M * γ_x) + σ_θ**2)\n", " label_string = f\"$M = {M}$\"\n", " ax.plot(γ, γ_next, lw=2, label=label_string)\n", "ax.legend(loc='lower right', fontsize=14)\n", "ax.set_xlabel(r'$\\gamma$', fontsize=16)\n", "ax.set_ylabel(r\"$\\gamma'$\", fontsize=16)\n", "ax.grid()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "8ab35603", "metadata": {}, "source": [ "The points where the curves hit the 45 degree lines are the long-run\n", "steady states corresponding to each $ M $, if that value of\n", "$ M $ was to remain fixed. As the number of firms falls, so does the\n", "long-run steady state of precision.\n", "\n", "Next let’s generate time series for beliefs and the aggregates – that\n", "is, the number of active firms and average output" ] }, { "cell_type": "code", "execution_count": null, "id": "0b86d477", "metadata": { "hide-output": false }, "outputs": [], "source": [ "sim_length=2000\n", "\n", "μ_vec = np.empty(sim_length)\n", "θ_vec = np.empty(sim_length)\n", "γ_vec = np.empty(sim_length)\n", "X_vec = np.empty(sim_length)\n", "M_vec = np.empty(sim_length)\n", "\n", "μ_vec[0] = econ.μ\n", "γ_vec[0] = econ.γ\n", "θ_vec[0] = 0\n", "\n", "w_shocks = np.random.randn(sim_length)\n", "\n", "for t in range(sim_length-1):\n", " X, M = econ.gen_aggregates()\n", " X_vec[t] = X\n", " M_vec[t] = M\n", "\n", " econ.update_beliefs(X, M)\n", " econ.update_θ(w_shocks[t])\n", "\n", " μ_vec[t+1] = econ.μ\n", " γ_vec[t+1] = econ.γ\n", " θ_vec[t+1] = econ.θ\n", "\n", "# Record final values of aggregates\n", "X, M = econ.gen_aggregates()\n", "X_vec[-1] = X\n", "M_vec[-1] = M" ] }, { "cell_type": "markdown", "id": "59ea0871", "metadata": {}, "source": [ "First, let’s see how well $ \\mu $ tracks $ \\theta $ in these\n", "simulations" ] }, { "cell_type": "code", "execution_count": null, "id": "5ed6f38b", "metadata": { "hide-output": false }, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(9, 6))\n", "ax.plot(range(sim_length), θ_vec, alpha=0.6, lw=2, label=r\"$\\theta$\")\n", "ax.plot(range(sim_length), μ_vec, alpha=0.6, lw=2, label=r\"$\\mu$\")\n", "ax.legend(fontsize=16)\n", "ax.grid()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "217715cf", "metadata": {}, "source": [ "Now let’s plot the whole thing together" ] }, { "cell_type": "code", "execution_count": null, "id": "9c3b1aa9", "metadata": { "hide-output": false }, "outputs": [], "source": [ "fig, axes = plt.subplots(4, 1, figsize=(12, 20))\n", "# Add some spacing\n", "fig.subplots_adjust(hspace=0.3)\n", "\n", "series = (θ_vec, μ_vec, γ_vec, M_vec)\n", "names = r'$\\theta$', r'$\\mu$', r'$\\gamma$', r'$M$'\n", "\n", "for ax, vals, name in zip(axes, series, names):\n", " # Determine suitable y limits\n", " s_max, s_min = max(vals), min(vals)\n", " s_range = s_max - s_min\n", " y_max = s_max + s_range * 0.1\n", " y_min = s_min - s_range * 0.1\n", " ax.set_ylim(y_min, y_max)\n", " # Plot series\n", " ax.plot(range(sim_length), vals, alpha=0.6, lw=2)\n", " ax.set_title(f\"time series for {name}\", fontsize=16)\n", " ax.grid()\n", "\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "5f35c4ff", "metadata": {}, "source": [ "If you run the code above you’ll get different plots, of course.\n", "\n", "Try experimenting with different parameters to see the effects on the time\n", "series.\n", "\n", "(It would also be interesting to experiment with non-Gaussian\n", "distributions for the shocks, but this is a big exercise since it takes\n", "us outside the world of the standard Kalman filter)" ] } ], "metadata": { "date": 1714442510.286287, "filename": "uncertainty_traps.md", "kernelspec": { "display_name": "Python", "language": "python3", "name": "python3" }, "title": "Uncertainty Traps" }, "nbformat": 4, "nbformat_minor": 5 }