{ "cells": [ { "cell_type": "markdown", "id": "c48466be", "metadata": {}, "source": [ "\n", "" ] }, { "cell_type": "markdown", "id": "1d085dfb", "metadata": {}, "source": [ "# Knowing the Forecasts of Others" ] }, { "cell_type": "markdown", "id": "d864d18e", "metadata": {}, "source": [ "## Contents\n", "\n", "- [Knowing the Forecasts of Others](#Knowing-the-Forecasts-of-Others) \n", " - [Introduction](#Introduction) \n", " - [The Setting](#The-Setting) \n", " - [Tactics](#Tactics) \n", " - [Equilibrium Conditions](#Equilibrium-Conditions) \n", " - [Equilibrium with $ \\theta_t $ stochastic but observed at $ t $](#Equilibrium-with-$-\\theta_t-$-stochastic-but-observed-at-$-t-$) \n", " - [Guess-and-Verify Tactic](#Guess-and-Verify-Tactic) \n", " - [Equilibrium with One Noisy Signal on $ \\theta_t $](#Equilibrium-with-One-Noisy-Signal-on-$-\\theta_t-$) \n", " - [Equilibrium with Two Noisy Signals on $ \\theta_t $](#Equilibrium-with-Two-Noisy-Signals-on-$-\\theta_t-$) \n", " - [Key Step](#Key-Step) \n", " - [An observed common shock benchmark](#An-observed-common-shock-benchmark) \n", " - [Comparison of All Signal Structures](#Comparison-of--All-Signal-Structures) \n", " - [Notes on History of the Problem](#Notes-on-History-of-the-Problem) " ] }, { "cell_type": "markdown", "id": "23431e9e", "metadata": {}, "source": [ "In addition to what’s in Anaconda, this lecture will need the following libraries:" ] }, { "cell_type": "code", "execution_count": null, "id": "69be5dcf", "metadata": { "hide-output": false }, "outputs": [], "source": [ "!pip install --upgrade quantecon\n", "!conda install -y -c plotly plotly plotly-orca" ] }, { "cell_type": "markdown", "id": "b28a7b6e", "metadata": {}, "source": [ "## Introduction\n", "\n", "Robert E. Lucas, Jr. [[REL75](https://python-advanced.quantecon.org/zreferences.html#id21)], Kenneth Kasa [[Kas00](https://python-advanced.quantecon.org/zreferences.html#id24)], and Robert Townsend\n", "[[Tow83](https://python-advanced.quantecon.org/zreferences.html#id25)] showed that putting decision makers into environments in which they want to infer persistent hidden state\n", "variables from equilibrium prices and quantities can\n", "elongate and amplify impulse responses to aggregate\n", "shocks.\n", "\n", "This provides a promising way to think about amplification mechanisms in business cycle models.\n", "\n", "Townsend [[Tow83](https://python-advanced.quantecon.org/zreferences.html#id25)]\n", "noted that living in such environments makes decision makers want to forecast forecasts of others.\n", "\n", "This theme has been pursued for situations in which\n", "decision makers’ imperfect information forces them to pursue an\n", "infinite recursion that involves forming beliefs about the beliefs of others\n", "(e.g., [[AMS02](https://python-advanced.quantecon.org/zreferences.html#id28)]).\n", "\n", "Lucas [[REL75](https://python-advanced.quantecon.org/zreferences.html#id21)] side stepped having decision makers forecast the\n", "forecasts of other decision makers by assuming that they simply **pool their\n", "information** before forecasting.\n", "\n", "A **pooling equilibrium** like Lucas’s plays a prominent role in this lecture.\n", "\n", "Because he didn’t assume such pooling, [[Tow83](https://python-advanced.quantecon.org/zreferences.html#id25)]\n", "confronted the forecasting the forecasts of others problem.\n", "\n", "To formulate the problem recursively required that Townsend define a decision maker’s **state** vector.\n", "\n", "Townsend concluded that his original model required an intractable infinite dimensional state space.\n", "\n", "Therefore, he constructed a more manageable approximating model in which a hidden Markov component of\n", "a demand shock is\n", "revealed to all firms after a fixed, finite number of periods.\n", "\n", "In this lecture, we illustrate again the theme that **finding the state is an art** by\n", "showing how to formulate Townsend’s original model in terms of a low-dimensional state space.\n", "\n", "We show that Townsend’s model shares equilibrium prices and quantities with those that\n", "prevail in a pooling equilibrium.\n", "\n", "That finding emerged from a line of research about Townsend’s model that built on [[PCL86](https://python-advanced.quantecon.org/zreferences.html#id23)] and that culminated in\n", "[[PS05](https://python-advanced.quantecon.org/zreferences.html#id22)] .\n", "\n", "Rather than directly deploying the [[PCL86](https://python-advanced.quantecon.org/zreferences.html#id23)] machinery here, we shall instead implement a sneaky\n", "**guess-and-verify** tactic.\n", "\n", "- We first compute a pooling equilibrium and represent it as an instance of a linear state-space system provided by\n", " the Python class `quantecon.LinearStateSpace`. \n", "- Leaving the state-transition equation for the pooling equilibrium unaltered, we alter the observation vector\n", " for a firm to match what it is in Townsend’s original model. So rather than directly observing the signal received by\n", " firms in the other industry, a firm sees the equilibrium price\n", " of the good produced by the other industry. \n", "- We compute a population linear least squares regression of the noisy signal at time $ t $ that firms in the other\n", " industry would receive in a pooling equilibrium on time $ t $ information that a firm receives in Townsend’s\n", " original model. \n", "- The $ R^2 $ in this regression equals $ 1 $. \n", "- That verifies that a firm’s information\n", " set in Townsend’s original model equals its information set in a pooling equilibrium. \n", "- Therefore, equilibrium\n", " prices and quantities in Townsend’s original model equal those in a pooling equilibrium. " ] }, { "cell_type": "markdown", "id": "ef81730a", "metadata": {}, "source": [ "### A Sequence of Models\n", "\n", "We proceed by describing a sequence of models of two industries that are linked in a\n", "single way:\n", "\n", "- shocks to the demand curves for their products have a common\n", " component. \n", "\n", "\n", "The models are simplified versions of Townsend’s [[Tow83](https://python-advanced.quantecon.org/zreferences.html#id25)].\n", "\n", "Townsend’s is a model of a rational expectations equilibrium in which firms want to **forecast forecasts of others**.\n", "\n", "In Townsend’s model, firms condition their forecasts on observed endogenous variables whose equilibrium laws of motion\n", "are determined by their own forecasting functions.\n", "\n", "We shall assemble model components progressively in ways that can help us to appreciate the structure of the\n", "**pooling equilibrium** that ultimately interests us.\n", "\n", "While keeping all other aspects of the model the same, we shall study\n", "consequences of alternative assumptions about what decision makers\n", "observe.\n", "\n", "Technically, this lecture deploys concepts and tools that appear\n", "in [First Look at Kalman Filter](https://python-intro.quantecon.org/kalman.html) and\n", "[Rational Expectations Equilibrium](https://python-intro.quantecon.org/rational_expectations.html)." ] }, { "cell_type": "markdown", "id": "29d0ee0a", "metadata": {}, "source": [ "## The Setting\n", "\n", "We cast all variables in terms of deviations from means.\n", "\n", "Therefore, we omit constants from inverse demand curves\n", "and other functions.\n", "\n", "Firms in industry $ i=1,2 $ use a single factor of\n", "production, capital $ k_t^i $, to produce output of a single good,\n", "$ y_t^i $.\n", "\n", "Firms bear quadratic costs of adjusting their capital stocks.\n", "\n", "A representative firm in industry $ i $ has production function\n", "$ y_t^i = f k_t^i $, $ f >0 $.\n", "\n", "The firm acts as a price taker with\n", "respect to output price $ P_t^i $, and maximizes\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " E_0^i \\sum_{t=0}^\\infty \\beta^t \\left\\{ P_t^i f k_t^i - .5\n", " h (k_{t+1}^i - k_t^i)^2 \\right\\} ,\n", " \\quad h >0 .\\end{aligned} \\tag{33.1}\n", "$$\n", "\n", "Demand in industry $ i $ is described by the inverse demand curve\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " P_t^i = - b Y_t^i + \\theta_t + \\epsilon_t^i , \\quad b >0,\n", " \\end{aligned} \\tag{33.2}\n", "$$\n", "\n", "where $ P_t^i $ is the price of good $ i $ at $ t $,\n", "$ Y_t^i = f K_t^i $ is output in market $ i $, $ \\theta_t $\n", "is a persistent component of a demand shock that is common across the\n", "two industries, and $ \\epsilon_t^i $ is an industry specific\n", "component of the demand shock that is i.i.d. and whose time $ t $\n", "marginal distribution is $ {\\mathcal N}(0, \\sigma_{\\epsilon}^2) $.\n", "\n", "We assume that $ \\theta_t $ is governed by\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " \\theta_{t+1} = \\rho \\theta_t + v_{t}\n", " \\end{aligned} \\tag{33.3}\n", "$$\n", "\n", "where $ \\{v_{t}\\} $ is an i.i.d. sequence of Gaussian shocks, each\n", "with mean zero and variance $ \\sigma_v^2 $.\n", "\n", "To simplify notation, we’ll study a special case by setting\n", "$ h=f=1 $.\n", "\n", "Costs of adjusting their capital stocks impart to firms an incentive to forecast the price of the\n", "good that they sell.\n", "\n", "Throughout, we use the **rational expectations** equilibrium concept presented\n", "in this lecture [Rational Expectations Equilibrium](https://python-intro.quantecon.org/rational_expectations.html).\n", "\n", "We let capital letters denote market wide objects and lower case letters\n", "denote objects chosen by a representative firm.\n", "\n", "In each industry, a competitive equilibrium prevails.\n", "\n", "To rationalize the big $ K $, little $ k $ connection, we can\n", "think of there being a continuum of firms in industry $ i $, with each firm being indexed by\n", "$ \\omega \\in [0,1] $ and\n", "$ K^i = \\int_0^1 k^i(\\omega) d \\omega $.\n", "\n", "In equilibrium, $ k_t^i = K_t^i $, but we must distinguish\n", "between $ k_t^i $ and $ K_t^i $ when we pose the firm’s\n", "optimization problem." ] }, { "cell_type": "markdown", "id": "2a81c727", "metadata": {}, "source": [ "## Tactics\n", "\n", "We shall compute\n", "equilibrium laws of motion for capital in industry $ i $ under a\n", "sequence of assumptions about what a representative firm observes.\n", "\n", "Successive members of this sequence make a representative firm’s\n", "information more and more obscure.\n", "\n", "We begin with the most information, then gradually withdraw information\n", "in a way that approaches and eventually reaches the Townsend-like information\n", "structure that we are ultimately interested in.\n", "\n", "Thus, we shall compute equilibria under the following alternative\n", "information structures:\n", "\n", "- **Perfect foresight:** future values of\n", " $ \\theta_t, \\epsilon_{t}^i $ are observed in industry $ i $. \n", "- **Observed history of stochastic** $ \\theta_t $:\n", " $ \\{\\theta_t, \\epsilon_{t}^i\\} $ are realizations from a\n", " stochastic process; current and past values of each are observed at\n", " time $ t $ but future values are not. \n", "- **One noise-ridden observation on** $ \\theta_t $: values of\n", " $ \\{\\theta_t, \\epsilon_{t}^i\\} $ separately are never observed. However, at\n", " time $ t $, a history $ w^t $ of scalar noise-ridden\n", " observations on $ \\theta_t $ is observed at time $ t $. \n", "- **Two noise-ridden observations on** $ \\theta_t $: values of\n", " $ \\{\\theta_t, \\epsilon_{t}^i\\} $ separately are never observed. However, at\n", " time $ t $, a history $ w^t $ of *two* noise-ridden\n", " observations on $ \\theta_t $ is observed at time $ t $. \n", "\n", "\n", "Successive computations build one on previous ones.\n", "\n", "We proceed by first finding an equilibrium under perfect foresight.\n", "\n", "To compute an equilibrium with current and past but not future values of $ \\theta_t $ observed, we use a\n", "*certainty equivalence principle* to justify modifying the perfect\n", "foresight equilibrium by replacing future values of\n", "$ \\theta_s, \\epsilon_{s}^i, s \\geq t $ with mathematical\n", "expectations conditioned on $ \\theta_t $.\n", "\n", "This provides the equilibrium when $ \\theta_t $ is observed at\n", "$ t $ but future $ \\theta_{t+j} $ and\n", "$ \\epsilon_{t+j}^i $ are not observed.\n", "\n", "To find an equilibrium when a history $ w^t $ observations of a **single** noise-ridden\n", "$ \\theta_t $ is observed, we again apply a\n", "certainty equivalence principle and replace future values of the random\n", "variables $ \\theta_s, \\epsilon_{s}^i, s \\geq t $ with their\n", "mathematical expectations conditioned on $ w^t $.\n", "\n", "To find an equilibrium when a history $ w^t $ of **two** noisy\n", "signals on $ \\theta_t $ is observed, we replace future values of the\n", "random variables $ \\theta_s, \\epsilon_{s}^i, s \\geq t $ with their\n", "mathematical expectations conditioned on history $ w^t $.\n", "\n", "We call the equilibrium with two noise-ridden observations on $ \\theta_t $ a **pooling equilibrium**.\n", "\n", "- It corresponds to an arrangement in which at the beginning of each\n", " period firms in industries $ 1 $ and $ 2 $ somehow get\n", " together and share information about current values of their noisy\n", " signals on $ \\theta $. \n", "\n", "\n", "We want ultimately to compare outcomes in a pooling equilibrium\n", "with an equilibrium under the following alternative information structure for a firm\n", "in industry $ i $ that originally interested Townsend [[Tow83](https://python-advanced.quantecon.org/zreferences.html#id25)]:\n", "\n", "- **Firm** $ i $’s **noise-ridden signal on** $ \\theta_t $ **and the\n", " price in industry** $ -i $, a firm in industry\n", " $ i $ observes a history $ w^t $ of *one* noise-ridden signal\n", " on $ \\theta_t $ and a history of industry $ -i $’s price is\n", " observed. (Here $ -i $ means ``not $ i $’’.) \n", "\n", "\n", "With this information structure, a representative firm $ i $ sees the price as well as the\n", "aggregate endogenous state variable $ Y_t^i $ in its own industry.\n", "\n", "That allows it to infer\n", "the total demand shock $ \\theta_t + \\epsilon_{t}^i $.\n", "\n", "However, at time $ t $, the firm sees only $ P_t^{-i} $ and does\n", "not see $ Y_t^{-i} $, so that a firm in industry $ i $ does not **directly**\n", "observe $ \\theta_t + \\epsilon_t^{-i} $.\n", "\n", "Nevertheless, it will turn out that equilibrium prices and quantities in this equilibrium equal\n", "their counterparts in a pooling equilibrium because\n", "firms in industry $ i $ are able to infer the noisy signal about the demand shock\n", "received by firms in industry $ -i $.\n", "\n", "We shall verify this assertion by using a guess and verify tactic that involves running a least\n", "squares regression and inspecting its $ R^2 $. [1]" ] }, { "cell_type": "markdown", "id": "66202b7f", "metadata": {}, "source": [ "## Equilibrium Conditions\n", "\n", "It is convenient to solve a firm’s problem without\n", "uncertainty by forming the Lagrangian:\n", "\n", "$$\n", "\\begin{aligned}\n", "J=\\sum_{t=0}^\\infty \\beta^t \\left\\{\n", "P_t^i k_t^i - .5 (\\mu_t^i)^2 + \\phi_t^i \\left[\n", " k_t^i + \\mu_t^i - k_{t+1}^i \\right] \\right\\} \\end{aligned}\n", "$$\n", "\n", "where $ \\{\\phi_t^i\\} $ is a sequence of Lagrange multipliers on the\n", "transition law $ k_{t+1}^i = k_{t}^i + \\mu_t^i $.\n", "\n", "First order conditions for the\n", "nonstochastic problem are\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " \\phi_t^i & = \\beta \\phi_{t+1}^i + \\beta P_{t+1}^i \\\\\n", " \\mu_t^i & = \\phi_t^i . \\end{aligned} \\tag{33.4}\n", "$$\n", "\n", "Substituting the demand function [(33.2)](#equation-town2) for\n", "$ P_t^i $, imposing the condition $ k_t^i = K_t^i $ that makes representative firm be\n", "representative, and using definition [(33.6)](#equation-town7)\n", "of $ g_t^i $, the Euler equation [(33.4)](#equation-town4) lagged\n", "by one period can be expressed as\n", "$ - b k_t^i + \\theta_t + \\epsilon_t^i + (k_{t+1}^i - k_t^i) - g_t^i =0 $\n", "or\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " k_{t+1}^i = (b+1) k_t^i - \\theta_t - \\epsilon_t^i + g_t^i\n", " \\end{aligned} \\tag{33.5}\n", "$$\n", "\n", "where we define $ g_t^i $ by\n", "\n", "\n", "\n", "$$\n", "g_t^i = \\beta^{-1} (k_t^i - k_{t-1}^i) \\tag{33.6}\n", "$$\n", "\n", "We can write Euler equation [(33.4)](#equation-town4) as:\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " g_t^i = P_t^i + \\beta g_{t+1}^i\n", " \\end{aligned} \\tag{33.7}\n", "$$\n", "\n", "In addition, we have the law of motion for $ \\theta_t $,\n", "[(33.3)](#equation-town2a), and the demand equation\n", "[(33.2)](#equation-town2).\n", "\n", "In summary, with perfect foresight, equilibrium conditions for industry\n", "$ i $ comprise the following system of difference equations:\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " k_{t+1}^i & = (1+b)k_t^i - \\epsilon_t^i -\\theta_t + g_t^i \\\\\n", " \\theta_{t+1} & = \\rho \\theta_t + v_t \\\\\n", " g_{t+1}^i & = \\beta^{-1} (g_t^i - P_t^i) \\\\\n", " P_t^i & = -b k_t^i + \\epsilon_t^i + \\theta_t \\end{aligned} \\tag{33.8}\n", "$$\n", "\n", "Without perfect foresight, the same system prevails except that the\n", "following equation replaces the third equation of [(33.8)](#equation-sol1):\n", "\n", "$$\n", "\\begin{aligned}\n", "g_{t+1,t}^i = \\beta^{-1} (g_t^i - P_t^i) \\end{aligned}\n", "$$\n", "\n", "where\n", "$ x_{t+1,t} $ denotes the mathematical expectation of\n", "$ x_{t+1} $ conditional on information at time $ t $." ] }, { "cell_type": "markdown", "id": "09f8c2e4", "metadata": {}, "source": [ "### Equilibrium under perfect foresight\n", "\n", "Our first step is to compute the equilibrium law of motion for\n", "$ k_t^i $ under perfect foresight.\n", "\n", "Let $ L $ be the lag\n", "operator. [2]\n", "\n", "Equations [(33.7)](#equation-pcl10) and [(33.5)](#equation-pcl11)\n", "imply the second order difference equation in\n", "$ k_t^i $: [3]\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " \\left[ (L^{-1} - (1+b))(1-\\beta L^{-1}) + b\\right] k_t^i\n", " = \\beta L^{-1} \\epsilon_t^i + \\beta L^{-1} \\theta_t .\n", " \\end{aligned} \\tag{33.9}\n", "$$\n", "\n", "Factor the polynomial in $ L $ on the left side as:\n", "\n", "$$\n", "\\begin{aligned}\n", "-\\beta [L^{-2} -(\\beta^{-1} + (1+b))L^{-1} + \\beta^{-1}]\n", "= \\tilde \\lambda^{-1}(L^{-1} - \\tilde \\lambda)(1-\\tilde \\lambda \\beta L^{-1})\n", "\\end{aligned}\n", "$$\n", "\n", "where $ |\\tilde \\lambda | < 1 $ is the smaller root and\n", "$ \\lambda $ is the larger root of\n", "$ (\\lambda-1)(\\lambda-1/\\beta)=b\\lambda $.\n", "\n", "Therefore, [(33.9)](#equation-euler1) can be expressed as\n", "\n", "$$\n", "\\begin{aligned}\n", "\\tilde \\lambda^{-1}(L^{-1} - \\tilde \\lambda) (1-\\tilde \\lambda \\beta L^{-1})\n", "k_t^i = \\beta L^{-1} \\epsilon_t^i + \\beta L^{-1} \\theta_t .\n", "\\end{aligned}\n", "$$\n", "\n", "Solving the stable root backwards and the unstable root forwards gives\n", "\n", "$$\n", "\\begin{aligned}\n", "k_{t+1}^i = \\tilde \\lambda k_t^i + {\\tilde \\lambda \\beta \\over 1 -\\tilde\n", "\\lambda \\beta L^{-1}}\n", "(\\epsilon_{t+1}^i + \\theta_{t+1} ) .\n", "\\end{aligned}\n", "$$\n", "\n", "Recall that we have already set $ k^i = K^i $ at the appropriate point in the argument, namely, *after* having derived the first-order necessary\n", "conditions for a representative firm in industry $ i $.\n", "\n", "Thus, under perfect foresight the equilibrium capital stock in industry $ i $ satisfies\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " k_{t+1}^i = \\tilde \\lambda k_t^i + \\sum_{j=1}^\\infty (\\tilde \\lambda \\beta)^j\n", " (\\epsilon_{t+j}^i + \\theta_{t+j}) .\n", " \\end{aligned} \\tag{33.10}\n", "$$\n", "\n", "Next, we shall investigate consequences of replacing future values of\n", "$ (\\epsilon_{t+j}^i + \\theta_{t+j}) $ in equation [(33.10)](#equation-town5) with alternative forecasting schemes.\n", "\n", "In particular, we shall compute equilibrium laws of motion for capital\n", "under alternative assumptions about information available to\n", "firms in market $ i $." ] }, { "cell_type": "markdown", "id": "76467380", "metadata": {}, "source": [ "## Equilibrium with $ \\theta_t $ stochastic but observed at $ t $\n", "\n", "If future $ \\theta $’s are unknown at $ t $, it is appropriate\n", "to replace all random variables on the right side of\n", "[(33.10)](#equation-town5) with their conditional expectations based on\n", "the information available to decision makers in market $ i $.\n", "\n", "For now, we assume that this information set is\n", "$ I_t^p = \\begin{bmatrix} \\theta^t & \\epsilon^{it} \\end{bmatrix} $,\n", "where $ z^t $ represents the semi-infinite history of variable\n", "$ z_s $ up to time $ t $.\n", "\n", "Later we shall give firms less information.\n", "\n", "To obtain an appropriate counterpart to [(33.10)](#equation-town5) under our\n", "current assumption about information, we apply a certainty equivalence\n", "principle.\n", "\n", "In particular, it is appropriate to take [(33.10)](#equation-town5) and\n", "replace each term $ ( \\epsilon_{t+j}^i+ \\theta_{t+j} ) $ on the\n", "right side with\n", "$ E[ (\\epsilon_{t+j}^i+ \\theta_{t+j}) \\vert \\theta^t ] $.\n", "\n", "After using [(33.3)](#equation-town2a) and the i.i.d. assumption about\n", "$ \\{\\epsilon_t^i\\} $, this gives\n", "\n", "$$\n", "\\begin{aligned}\n", "k_{t+1}^i = \\tilde \\lambda k_t^i + {\\tilde \\lambda \\beta \\rho \\over 1 -\n", "\\tilde \\lambda \\beta \\rho }\n", "\\theta_t\n", "\\end{aligned}\n", "$$\n", "\n", "or\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " k_{t+1}^i = \\tilde \\lambda k_t^i + {\\rho \\over \\lambda - \\rho} \\theta_t\n", " \\end{aligned} \\tag{33.11}\n", "$$\n", "\n", "where $ \\lambda \\equiv (\\beta \\tilde \\lambda)^{-1} $.\n", "\n", "For our purposes, it is convenient to represent the equilibrium\n", "$ \\{k_t^i\\}_t $ process recursively as\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " k_{t+1}^i & = \\tilde \\lambda k_t^i + {1 \\over \\lambda - \\rho}\n", " \\hat \\theta_{t+1} \\\\\n", " \\hat \\theta_{t+1} & = \\rho \\theta_t \\\\\n", " \\theta_{t+1} & = \\rho \\theta_t + v_t. \\end{aligned} \\tag{33.12}\n", "$$" ] }, { "cell_type": "markdown", "id": "03d0f149", "metadata": {}, "source": [ "### Filtering" ] }, { "cell_type": "markdown", "id": "c4cf687c", "metadata": {}, "source": [ "#### One noisy signal\n", "\n", "We get closer to the original Townsend model that interests us by now\n", "assuming that firms in market $ i $ do not observe $ \\theta_t $.\n", "\n", "Instead they observe a history $ w^t $ of noisy signals at time $ t $.\n", "\n", "In particular, assume that\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " w_t & = \\theta_t + e_t \\\\\n", " \\theta_{t+1} & = \\rho \\theta_t + v_t\n", " \\end{aligned} \\tag{33.13}\n", "$$\n", "\n", "where $ e_t $ and $ v_t $ are mutually independent\n", "i.i.d. Gaussian shock processes with means of zero and variances\n", "$ \\sigma_e^2 $ and $ \\sigma_v^2 $, respectively.\n", "\n", "Define\n", "\n", "$$\n", "\\begin{aligned}\n", "\\hat \\theta_{t+1} = E(\\theta_{t+1} | w^t)\n", "\\end{aligned}\n", "$$\n", "\n", "where $ w^t = [w_t, w_{t-1}, \\ldots, w_0] $ denotes the history of the $ w_s $ process up to\n", "and including $ t $.\n", "\n", "Associated with the state-space representation\n", "[(33.13)](#equation-kf1-2) is the time-invariant *innovations\n", "representation*\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " \\hat \\theta_{t+1} & = \\rho \\hat \\theta_t + \\kappa a_t \\\\\n", " w_t & = \\hat \\theta_t + a_t\n", " \\end{aligned} \\tag{33.14}\n", "$$\n", "\n", "where $ a_t \\equiv w_t - E(w_t | w^{t-1}) $ is the *innovations*\n", "process in $ w_t $ and the Kalman gain $ \\kappa $ is\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " \\kappa = {\\rho p \\over p + \\sigma_e^2} \\end{aligned} \\tag{33.15}\n", "$$\n", "\n", "and where $ p $ satisfies the Riccati equation\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " p = \\sigma_v^2 + { p \\rho^2 \\sigma_e^2 \\over \\sigma_e^2 + p}.\n", " \\end{aligned} \\tag{33.16}\n", "$$" ] }, { "cell_type": "markdown", "id": "effb3e10", "metadata": {}, "source": [ "#### State-reconstruction error\n", "\n", "Define the state *reconstruction error* $ \\tilde \\theta_t $ by\n", "\n", "$$\n", "\\begin{aligned}\n", "\\tilde \\theta_t = \\theta_t - \\hat \\theta_t .\n", "\\end{aligned}\n", "$$\n", "\n", "Then $ p = E \\tilde \\theta_t^2 $.\n", "\n", "Equations [(33.13)](#equation-kf1-2) and [(33.14)](#equation-kf3-4) imply\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " \\tilde \\theta_{t+1} = (\\rho - \\kappa) \\tilde \\theta_t + v_t - k e_t .\n", " \\end{aligned} \\tag{33.17}\n", "$$\n", "\n", "Notice that we can express $ \\hat \\theta_{t+1} $ as\n", "\n", "\n", "\n", "$$\n", "\\hat \\theta_{t+1} = [\\rho \\theta_t + v_t] + [ \\kappa e_t - (\\rho -\\kappa) \\tilde \\theta_t - v_t] , \\tag{33.18}\n", "$$\n", "\n", "where the first term in braces equals\n", "$ \\theta_{t+1} $ and the second term in braces equals\n", "$ -\\tilde \\theta_{t+1} $.\n", "\n", "We can express [(33.11)](#equation-solution1) as\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " k_{t+1}^i = \\tilde \\lambda k_t^i + {1 \\over \\lambda - \\rho}\n", " E \\theta_{t+1} | \\theta^t .\n", " \\end{aligned} \\tag{33.19}\n", "$$\n", "\n", "An application of a certainty equivalence principle asserts that when\n", "only $ w^t $ is observed, a corresponding equilibrium $ \\{k_t^i\\} $ process can be found by\n", "replacing the information set $ \\theta^t $ with $ w^t $ in\n", "[(33.19)](#equation-solution2).\n", "\n", "Making this substitution and using [(33.18)](#equation-kf8) leads to\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " k_{t+1}^i = \\tilde \\lambda k_t^i + {\\rho \\over \\lambda - \\rho} \\theta_t + {\\kappa \\over \\lambda - \\rho} e_t - {\\rho - \\kappa \\over \\lambda - \\rho} \\tilde \\theta_t .\n", " \\end{aligned} \\tag{33.20}\n", "$$\n", "\n", "Simplifying equation [(33.18)](#equation-kf8), we also have\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " \\hat \\theta_{t+1} = \\rho \\theta_t + \\kappa e_t - (\\rho -\\kappa) \\tilde \\theta_t .\n", " \\end{aligned} \\tag{33.21}\n", "$$\n", "\n", "Equations [(33.20)](#equation-kf9), [(33.21)](#equation-kf8a) describe\n", "an equilibrium when $ w^t $ is observed." ] }, { "cell_type": "markdown", "id": "5d1d5207", "metadata": {}, "source": [ "### A new state variable\n", "\n", "Relative to [(33.11)](#equation-solution1), the equilibrium acquires a **new\n", "state variable**, namely, the $ \\theta $–reconstruction error,\n", "$ \\tilde \\theta_t $.\n", "\n", "For a subsequent argument, by using [(33.15)](#equation-kal1), it is convenient to\n", "write [(33.20)](#equation-kf9) as\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " k_{t+1}^i = \\tilde \\lambda k_t^i + {\\rho \\over \\lambda - \\rho } \\theta_t + {1 \\over \\lambda - \\rho} {p \\rho \\over p + \\sigma_e^2} e_t - {1 \\over \\lambda - \\rho} {\\rho \\sigma_e^2 \\over p + \\sigma_e^2}\n", " \\tilde \\theta_t\n", " \\end{aligned} \\tag{33.22}\n", "$$\n", "\n", "In summary, when decision makers in market $ i $ observe a semi-infinite history $ w^t $ of noisy\n", "signals $ w_t $ on $ \\theta_t $ at $ t $, we an\n", "equilibrium law of motion for $ k_t^i $ can be represented as\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", "k_{t+1}^i & = \\tilde \\lambda k_t^i + {1 \\over \\lambda - \\rho} \\hat \\theta_{t+1} \\\\\n", "\\hat \\theta_{t+1} & = \\rho \\theta_t + {\\rho p \\over p + \\sigma_e^2} e_t - {\\rho \\sigma_e^2 \\over p + \\sigma_e^2} \\tilde \\theta_t \\\\\n", "\\tilde \\theta_{t+1} & = { \\rho \\sigma_e^2 \\over p + \\sigma_e^2} \\tilde\n", " \\theta_t - {p \\rho \\over p + \\sigma_e^2} e_t + v_t \\\\\n", "\\theta_{t+1} & = \\rho \\theta_t + v_t . \\end{aligned} \\tag{33.23}\n", "$$" ] }, { "cell_type": "markdown", "id": "89bae334", "metadata": {}, "source": [ "### Two Noisy Signals\n", "\n", "We now construct a **pooling equilibrium** by assuming that at time $ t $ a firm in\n", "industry $ i $ receives a vector $ w_t $ of *two* noisy signals\n", "on $ \\theta_t $:\n", "\n", "$$\n", "\\begin{aligned}\n", "\\theta_{t+1} & = \\rho\\theta_{t}+v_{t} \\\\\n", "w_{t} & = \\begin{bmatrix}1 \\\\\n", "1\n", "\\end{bmatrix}\\theta_{t}+\\begin{bmatrix}e_{1t} \\\\\n", "e_{2t}\n", "\\end{bmatrix}\n", "\\end{aligned}\n", "$$\n", "\n", "To justify that we are constructing is a **pooling equilibrium** we can\n", "assume that\n", "\n", "$$\n", "\\begin{aligned}\n", "\\begin{bmatrix} e_{1t} \\\\ e_{2t} \\end{bmatrix} =\n", "\\begin{bmatrix} \\epsilon_{t}^1 \\\\ \\epsilon_{t}^2 \\end{bmatrix}\n", "\\end{aligned}\n", "$$\n", "\n", "so that a firm in industry $ i $ observes the noisy signals on that\n", "$ \\theta_t $ presented to firms in both industries $ i $ and\n", "$ -i $.\n", "\n", "The pertinent innovations representation now becomes\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " \\hat \\theta_{t+1} & = \\rho\n", " \\hat \\theta_t + \\kappa a_t \\\\\n", " w_t & = \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} \\hat \\theta_t + a_t\n", " \\end{aligned} \\tag{33.24}\n", "$$\n", "\n", "where $ a_t \\equiv w_t - E [w_t | w^{t-1}] $ is a\n", "$ (2 \\times 1) $ vector of innovations in $ w_t $ and $ \\kappa $\n", "is now a $ (1 \\times 2) $ vector of Kalman gains.\n", "\n", "Formulas for the Kalman filter imply that\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " \\kappa ={ \\rho p \\over 2 p + \\sigma_e^2}\n", " \\begin{bmatrix}1 & 1 \\end{bmatrix}\n", " \\end{aligned} \\tag{33.25}\n", "$$\n", "\n", "where $ p = E \\tilde \\theta_t \\tilde \\theta_t^T $ now satisfies the\n", "Riccati equation\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", " p = \\sigma_v^2 + {p \\rho^2 \\sigma_e^2 \\over 2 p + \\sigma_e^2}.\n", " \\end{aligned} \\tag{33.26}\n", "$$\n", "\n", "Thus, when a representative firm in industry $ i $ observes *two*\n", "noisy signals on $ \\theta_t $, we can express the equilibrium law of\n", "motion for capital recursively as\n", "\n", "\n", "\n", "$$\n", "\\begin{aligned}\n", "k_{t+1}^i & = \\tilde \\lambda k_t^i + {1 \\over \\lambda - \\rho}\\hat \\theta_{t+1} \\\\\n", "\\hat \\theta_{t+1} & = \\rho \\theta_t + {\\rho p \\over 2 p + \\sigma_e^2} (e_{1t}+e_{2t}) - {\\rho \\sigma_e^2 \\over 2 p + \\sigma_e^2} \\tilde \\theta_t \\\\\n", "\\tilde \\theta_{t+1} & = { \\rho \\sigma_e^2 \\over 2 p + \\sigma_e^2} \\tilde \\theta_t - {p \\rho \\over 2 p + \\sigma_e^2}(e_{1t}+e_{2t}) +v_t \\\\\n", "\\theta_{t+1} & = \\rho \\theta_t + v_t .\n", " \\end{aligned} \\tag{33.27}\n", "$$\n", "\n", "Below, by using a guess-and-verify tactic, we shall show that outcomes in this **pooling equilibrium** equal those in an equilibrium under the alternative\n", "information structure that interested Townsend [[Tow83](https://python-advanced.quantecon.org/zreferences.html#id25)] but that originally seemed too challenging to compute. [4]" ] }, { "cell_type": "markdown", "id": "a9dc655e", "metadata": {}, "source": [ "## Guess-and-Verify Tactic\n", "\n", "As a preliminary step we shall take our recursive representation [(33.23)](#equation-sol0a)\n", "of an equilibrium in industry $ i $ with one noisy signal\n", "on $ \\theta_t $ and perform the following steps:\n", "\n", "- Compute $ \\lambda $ and $ \\tilde{\\lambda} $ by posing a\n", " root-finding problem and solving it with `numpy.roots` \n", "- Compute $ p $ by forming the appropriate discrete Riccati equation and then solving it\n", " using `quantecon.solve_discrete_riccati` \n", "- Add a *measurement equation* for\n", " $ P_t^i = b k_t^i + \\theta_t + e_t $, $ \\theta_t + e_t $,\n", " and $ e_t $ to system [(33.23)](#equation-sol0a). \n", "- Write the resulting system\n", " in state-space form and encode it using `quantecon.LinearStateSpace` \n", "- Use methods of the `quantecon.LinearStateSpace` to compute impulse response\n", " functions of $ k_t^i $ with respect to shocks $ v_t, e_t $. \n", "\n", "\n", "After analyzing the one-noisy-signal structure in this way, by making appropriate modifications\n", "we shall analyze the two-noisy-signal\n", "structure.\n", "\n", "We proceed to analyze first the one-noisy-signal structure and then the two-noisy-signal structure." ] }, { "cell_type": "markdown", "id": "d8cbd3ea", "metadata": {}, "source": [ "## Equilibrium with One Noisy Signal on $ \\theta_t $" ] }, { "cell_type": "markdown", "id": "bc83fa67", "metadata": {}, "source": [ "### Step 1: Solve for $ \\tilde{\\lambda} $ and $ \\lambda $\n", "\n", "1. Cast\n", " $ \\left(\\lambda-1\\right)\\left(\\lambda-\\frac{1}{\\beta}\\right)=b\\lambda $\n", " as $ p\\left(\\lambda\\right)=0 $ where $ p $ is a polynomial\n", " function of $ \\lambda $. \n", "1. Use `numpy.roots` to solve for the roots of $ p $ \n", "1. Verify $ \\lambda \\approx \\frac{1}{\\beta\\tilde{\\lambda}} $ \n", "\n", "\n", "Note that\n", "$ p\\left(\\lambda\\right)=\\lambda^{2}-\\left(1+b+\\frac{1}{\\beta}\\right)\\lambda+\\frac{1}{\\beta} $." ] }, { "cell_type": "markdown", "id": "9a71d8c7", "metadata": {}, "source": [ "### Step 2: Solve for $ p $\n", "\n", "1. Cast\n", " $ p=\\sigma_{v}^{2}+\\frac{p\\rho^{2}\\sigma_{e}^{2}}{2p+\\sigma_{e}^{2}} $\n", " as a discrete matrix Riccati equation. \n", "1. Use `quantecon.solve_discrete_riccati` to solve for $ p $ \n", "1. Verify\n", " $ p \\approx\\sigma_{v}^{2}+\\frac{p\\rho^{2}\\sigma_{e}^{2}}{2p+\\sigma_{e}^{2}} $ \n", "\n", "\n", "Note that:\n", "\n", "$$\n", "\\begin{aligned}\n", " A & = & \\left[\\begin{array}{c}\n", " \\rho\\end{array}\\right]\\\\\n", " B & = & \\left[\\begin{array}{c}\n", " \\sqrt{2}\\end{array}\\right]\\\\\n", " R & = & \\left[\\begin{array}{c}\n", " \\sigma_{e}^{2}\\end{array}\\right]\\\\\n", " Q & = & \\left[\\begin{array}{c}\n", " \\sigma_{v}^{2}\\end{array}\\right]\\\\\n", " N & = & \\left[\\begin{array}{c}\n", " 0\\end{array}\\right]\n", "\\end{aligned}\n", "$$" ] }, { "cell_type": "markdown", "id": "e8cbf113", "metadata": {}, "source": [ "### Step 3: Represent the system using `quantecon.LinearStateSpace`\n", "\n", "We use the following representation for constructing the\n", "`quantecon.LinearStateSpace` instance.\n", "\n", "$$\n", "\\begin{aligned}\n", "\\underbrace{\\left[\\begin{array}{c}\n", "e_{t+1}\\\\\n", "k_{t+1}^{i}\\\\\n", "\\tilde{\\theta}_{t+1}\\\\\n", "P_{t+1}\\\\\n", "\\theta_{t+1}\\\\\n", "v_{t+1}\n", "\\end{array}\\right]}_{x_{t+1}} & = \\underbrace{\\left[\\begin{array}{cccccc}\n", "0 & 0 & 0 & 0 & 0 & 0\\\\\n", "\\frac{\\kappa}{\\lambda-\\rho} & \\tilde{\\lambda} & \\frac{-1}{\\lambda-\\rho}\\frac{\\kappa\\sigma_{e}^{2}}{p} & 0 & \\frac{\\rho}{\\lambda-\\rho} & 0\\\\\n", "-\\kappa & 0 & \\frac{\\kappa\\sigma_{e}^{2}}{p} & 0 & 0 & 1\\\\\n", "\\frac{b\\kappa}{\\lambda-\\rho} & b\\tilde{\\lambda} & \\frac{-b}{\\lambda-\\rho}\\frac{\\kappa\\sigma_{e}^{2}}{p} & 0 & \\frac{b\\rho}{\\lambda-\\rho}+\\rho & 1\\\\\n", "0 & 0 & 0 & 0 & \\rho & 1\\\\\n", "0 & 0 & 0 & 0 & 0 & 0\n", "\\end{array}\\right]}_{A}\\underbrace{\\left[\\begin{array}{c}\n", "e_{t}\\\\\n", "k_{t}^{i}\\\\\n", "\\tilde{\\theta}_{t}\\\\\n", "P_{t}\\\\\n", "\\theta_{t}\\\\\n", "v_{t}\n", "\\end{array}\\right]}_{x_{t}}+\\underbrace{\\left[\\begin{array}{cc}\n", "\\sigma_{e} & 0\\\\\n", "0 & 0\\\\\n", "0 & 0\\\\\n", "\\sigma_{e} & 0\\\\\n", "0 & 0\\\\\n", "0 & \\sigma_{v}\n", "\\end{array}\\right]}_{C}\\left[\\begin{array}{c}\n", "z_{1,t+1}\\\\\n", "z_{2,t+1}\n", "\\end{array}\\right]\\\\\n", "\\underbrace{\\left[\\begin{array}{c}\n", "P_{t}\\\\\n", "e_{t}+\\theta_{t}\\\\\n", "e_{t}\n", "\\end{array}\\right]}_{y_{t}} & = \\underbrace{\\left[\\begin{array}{cccccc}\n", "0 & 0 & 0 & 1 & 0 & 0\\\\\n", "1 & 0 & 0 & 0 & 1 & 0\\\\\n", "1 & 0 & 0 & 0 & 0 & 0\n", "\\end{array}\\right]}_{G}\\underbrace{\\left[\\begin{array}{c}\n", "e_{t}\\\\\n", "k_{t}^{i}\\\\\n", "\\tilde{\\theta}_{t}\\\\\n", "P_{t}\\\\\n", "\\theta_{t}\\\\\n", "v_{t}\n", "\\end{array}\\right]}_{x_{t}}+\\underbrace{\\left[\\begin{array}{c}\n", "0\\\\\n", "0\\\\\n", "0\n", "\\end{array}\\right]}_{H}w_{t+1}\\\\\n", "\\left[\\begin{array}{c}\n", "z_{1,t+1}\\\\\n", "z_{2,t+1}\\\\\n", "w_{t+1}\n", "\\end{array}\\right] & \\sim \\mathcal{N}\\left(0,I\\right)\\\\\n", "\\kappa & = \\frac{\\rho p}{p+\\sigma_{e}^{2}}\n", "\\end{aligned}\n", "$$\n", "\n", "This representation includes extraneous variables such as $ P_{t} $ in the\n", "state vector.\n", "\n", "We formulate things in this way because\n", "it allows us easily to compute covariances of these variables with other\n", "components of the state vector (step 5 above) by using the `stationary_distributions` method of the `LinearStateSpace` class." ] }, { "cell_type": "code", "execution_count": null, "id": "bf673705", "metadata": { "hide-output": false }, "outputs": [], "source": [ "import numpy as np\n", "import quantecon as qe\n", "import plotly.graph_objects as go\n", "import plotly.offline as pyo\n", "from statsmodels.regression.linear_model import OLS\n", "from IPython.display import display, Latex, Image\n", "\n", "pyo.init_notebook_mode(connected=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "6f692d18", "metadata": { "hide-output": false }, "outputs": [], "source": [ "β = 0.9 # Discount factor\n", "ρ = 0.8 # Persistence parameter for the hidden state\n", "b = 1.5 # Demand curve parameter\n", "σ_v = 0.5 # Standard deviation of shock to θ_t\n", "σ_e = 0.6 # Standard deviation of shocks to w_t" ] }, { "cell_type": "code", "execution_count": null, "id": "22c676e5", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Compute λ\n", "poly = np.array([1, -(1 + β + b) / β, 1 / β])\n", "roots_poly = np.roots(poly)\n", "λ_tilde = roots_poly.min()\n", "λ = roots_poly.max()" ] }, { "cell_type": "code", "execution_count": null, "id": "3c85f06f", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Verify that λ = (βλ_tilde) ^ (-1)\n", "tol = 1e-12\n", "np.max(np.abs(λ - 1 / (β * λ_tilde))) < tol" ] }, { "cell_type": "code", "execution_count": null, "id": "af529405", "metadata": { "hide-output": false }, "outputs": [], "source": [ "A_ricc = np.array([[ρ]])\n", "B_ricc = np.array([[1.]])\n", "R_ricc = np.array([[σ_e ** 2]])\n", "Q_ricc = np.array([[σ_v ** 2]])\n", "N_ricc = np.zeros((1, 1))\n", "p = qe.solve_discrete_riccati(A_ricc, B_ricc, Q_ricc, R_ricc, N_ricc).item()\n", "\n", "p_one = p # Save for comparison later" ] }, { "cell_type": "code", "execution_count": null, "id": "3411d29f", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Verify that p = σ_v ^ 2 + p * ρ ^ 2 - (ρ * p) ^ 2 / (p + σ_e ** 2)\n", "tol = 1e-12\n", "np.abs(p - (σ_v ** 2 + p * ρ ** 2 - (ρ * p) ** 2 / (p + σ_e ** 2))) < tol" ] }, { "cell_type": "code", "execution_count": null, "id": "334a9887", "metadata": { "hide-output": false }, "outputs": [], "source": [ "κ = ρ * p / (p + σ_e ** 2)\n", "κ_prod = κ * σ_e ** 2 / p\n", "\n", "κ_one = κ # Save for comparison later\n", "\n", "A_lss = np.array([[0., 0., 0., 0., 0., 0.],\n", " [κ / (λ - ρ), λ_tilde, -κ_prod / (λ - ρ), 0., ρ / (λ - ρ), 0.],\n", " [-κ, 0., κ_prod, 0., 0., 1.],\n", " [b * κ / (λ - ρ) , b * λ_tilde, -b * κ_prod / (λ - ρ), 0., b * ρ / (λ - ρ) + ρ, 1.],\n", " [0., 0., 0., 0., ρ, 1.],\n", " [0., 0., 0., 0., 0., 0.]])\n", "\n", "C_lss = np.array([[σ_e, 0.],\n", " [0., 0.],\n", " [0., 0.],\n", " [σ_e, 0.],\n", " [0., 0.],\n", " [0., σ_v]])\n", "\n", "G_lss = np.array([[0., 0., 0., 1., 0., 0.],\n", " [1., 0., 0., 0., 1., 0.],\n", " [1., 0., 0., 0., 0., 0.]])" ] }, { "cell_type": "code", "execution_count": null, "id": "0ab4377a", "metadata": { "hide-output": false }, "outputs": [], "source": [ "mu_0 = np.array([0., 0., 0., 0., 0., 0.])\n", "\n", "lss = qe.LinearStateSpace(A_lss, C_lss, G_lss, mu_0=mu_0)" ] }, { "cell_type": "code", "execution_count": null, "id": "18fdcc73", "metadata": { "hide-output": false }, "outputs": [], "source": [ "ts_length = 100_000\n", "x, y = lss.simulate(ts_length, random_state=1)" ] }, { "cell_type": "code", "execution_count": null, "id": "18d7d50a", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Verify that two ways of computing P_t match\n", "np.max(np.abs(np.array([[1., b, 0., 0., 1., 0.]]) @ x - x[3])) < 1e-12" ] }, { "cell_type": "markdown", "id": "88285020", "metadata": {}, "source": [ "### Step 4: Compute impulse response functions\n", "\n", "To compute impulse response functions of $ k_t^i $, we use the `impulse_response` method of the\n", "`quantecon.LinearStateSpace` class and plot outcomes." ] }, { "cell_type": "code", "execution_count": null, "id": "9fd0ef71", "metadata": { "hide-output": false }, "outputs": [], "source": [ "xcoef, ycoef = lss.impulse_response(j=21)\n", "data = np.array([xcoef])[0, :, 1, :]\n", "\n", "fig = go.Figure(data=go.Scatter(y=data[:-1, 0], name=r'$e_{t+1}$'))\n", "fig.add_trace(go.Scatter(y=data[1:, 1], name=r'$v_{t+1}$'))\n", "fig.update_layout(title=r'Impulse Response Function',\n", " xaxis_title='Time',\n", " yaxis_title=r'$k^{i}_{t}$')\n", "fig1 = fig\n", "# Export to PNG file\n", "Image(fig1.to_image(format=\"png\"))\n", "# fig1.show() will provide interactive plot when running\n", "# notebook locally" ] }, { "cell_type": "markdown", "id": "abc8972f", "metadata": {}, "source": [ "### Step 5: Compute stationary covariance matrices and population regressions\n", "\n", "We compute stationary covariance matrices by\n", "calling the `stationary_distributions` method of\n", "the `quantecon.LinearStateSpace` class.\n", "\n", "By appropriately decomposing the covariance matrix of the state vector, we obtain ingredients\n", "of pertinent population regression coefficients.\n", "\n", "Define\n", "\n", "$$\n", "\\Sigma_{x}=\\left[\\begin{array}{cc}\n", "\\Sigma_{11} & \\Sigma_{12}\\\\\n", "\\Sigma_{21} & \\Sigma_{22}\n", "\\end{array}\\right]\n", "$$\n", "\n", "where $ \\Sigma_{11} $ is the covariance matrix of dependent variables and $ \\Sigma_{22} $ is the covariance matrix of independent variables.\n", "\n", "Regression coefficients are $ \\beta=\\Sigma_{21}\\Sigma_{22}^{-1} $.\n", "\n", "To verify an instance of a law of large numbers computation, we construct a long simulation of\n", "the state vector and for the resulting sample compute\n", "the ordinary least-squares estimator of $ \\beta $ that we shall compare with corresponding population regression\n", "coefficients." ] }, { "cell_type": "code", "execution_count": null, "id": "622e5738", "metadata": { "hide-output": false }, "outputs": [], "source": [ "_, _, Σ_x, Σ_y, Σ_yx = lss.stationary_distributions()\n", "\n", "Σ_11 = Σ_x[0, 0]\n", "Σ_12 = Σ_x[0, 1:4]\n", "Σ_21 = Σ_x[1:4, 0]\n", "Σ_22 = Σ_x[1:4, 1:4]\n", "\n", "reg_coeffs = Σ_12 @ np.linalg.inv(Σ_22)\n", "\n", "print('Regression coefficients (e_t on k_t, P_t, \\\\tilde{\\\\theta_t})')\n", "print('------------------------------')\n", "print(r'k_t:', reg_coeffs[0])\n", "print(r'\\tilde{\\theta_t}:', reg_coeffs[1])\n", "print(r'P_t:', reg_coeffs[2])" ] }, { "cell_type": "code", "execution_count": null, "id": "9f353371", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Compute R squared\n", "R_squared = reg_coeffs @ Σ_x[1:4, 1:4] @ reg_coeffs / Σ_x[0, 0]\n", "R_squared" ] }, { "cell_type": "code", "execution_count": null, "id": "42fc05b1", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Verify that the computed coefficients are close to least squares estimates\n", "model = OLS(x[0], x[1:4].T)\n", "reg_res = model.fit()\n", "np.max(np.abs(reg_coeffs - reg_res.params)) < 1e-2" ] }, { "cell_type": "code", "execution_count": null, "id": "c0e37171", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Verify that R_squared matches least squares estimate\n", "np.abs(reg_res.rsquared - R_squared) < 1e-2" ] }, { "cell_type": "code", "execution_count": null, "id": "763c07eb", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Verify that θ_t + e_t can be recovered\n", "model = OLS(y[1], x[1:4].T)\n", "reg_res = model.fit()\n", "np.abs(reg_res.rsquared - 1.) < 1e-6" ] }, { "cell_type": "markdown", "id": "ad34f109", "metadata": {}, "source": [ "## Equilibrium with Two Noisy Signals on $ \\theta_t $\n", "\n", "Steps 1, 4, and 5 are identical to those for the one-noisy-signal structure.\n", "\n", "Step 2 requires a straightforward modification.\n", "\n", "For step 3, we construct the following state-space representation so that we can get our hands on\n", "all of the random processes that we require in order to compute a regression of the noisy signal about\n", "$ \\theta $ from the other industry that a firm receives directly in a pooling equilibrium against information that\n", "a firm would receive in Townsend’s original model.\n", "\n", "For this purpose, we include equilibrium goods prices from both industries in the state vector:\n", "\n", "$$\n", "\\begin{aligned}\n", "\\underbrace{\\left[\\begin{array}{c}\n", "e_{1,t+1}\\\\\n", "e_{2,t+1}\\\\\n", "k_{t+1}^{i}\\\\\n", "\\tilde{\\theta}_{t+1}\\\\\n", "P_{t+1}^{1}\\\\\n", "P_{t+1}^{2}\\\\\n", "\\theta_{t+1}\\\\\n", "v_{t+1}\n", "\\end{array}\\right]}_{x_{t+1}} & = \\underbrace{\\left[\\begin{array}{cccccccc}\n", "0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n", "0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n", "\\frac{\\kappa}{\\lambda-\\rho} & \\frac{\\kappa}{\\lambda-\\rho} & \\tilde{\\lambda} & \\frac{-1}{\\lambda-\\rho}\\frac{\\kappa\\sigma_{e}^{2}}{p} & 0 & 0 & \\frac{\\rho}{\\lambda-\\rho} & 0\\\\\n", "-\\kappa & -\\kappa & 0 & \\frac{\\kappa\\sigma_{e}^{2}}{p} & 0 & 0 & 0 & 1\\\\\n", "\\frac{b\\kappa}{\\lambda-\\rho} & \\frac{b\\kappa}{\\lambda-\\rho} & b\\tilde{\\lambda} & \\frac{-b}{\\lambda-\\rho}\\frac{\\kappa\\sigma_{e}^{2}}{p} & 0 & 0 & \\frac{b\\rho}{\\lambda-\\rho}+\\rho & 1\\\\\n", "\\frac{b\\kappa}{\\lambda-\\rho} & \\frac{b\\kappa}{\\lambda-\\rho} & b\\tilde{\\lambda} & \\frac{-b}{\\lambda-\\rho}\\frac{\\kappa\\sigma_{e}^{2}}{p} & 0 & 0 & \\frac{b\\rho}{\\lambda-\\rho}+\\rho & 1\\\\\n", "0 & 0 & 0 & 0 & 0 & 0 & \\rho & 1\\\\\n", "0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\n", "\\end{array}\\right]}_{A}\\underbrace{\\left[\\begin{array}{c}\n", "e_{1,t}\\\\\n", "e_{2,t}\\\\\n", "k_{t}^{i}\\\\\n", "\\tilde{\\theta}_{t}\\\\\n", "P_{t}^{1}\\\\\n", "P_{t}^{2}\\\\\n", "\\theta_{t}\\\\\n", "v_{t}\n", "\\end{array}\\right]}_{x_{t}}+\\underbrace{\\left[\\begin{array}{ccc}\n", "\\sigma_{e} & 0 & 0\\\\\n", "0 & \\sigma_{e} & 0\\\\\n", "0 & 0 & 0\\\\\n", "0 & 0 & 0\\\\\n", "\\sigma_{e} & 0 & 0\\\\\n", "0 & \\sigma_{e} & 0\\\\\n", "0 & 0 & 0\\\\\n", "0 & 0 & \\sigma_{v}\n", "\\end{array}\\right]}_{C}\\left[\\begin{array}{c}\n", "z_{1,t+1}\\\\\n", "z_{2,t+1}\\\\\n", "z_{3,t+1}\n", "\\end{array}\\right]\\\\\n", "\\underbrace{\\left[\\begin{array}{c}\n", "P_{t}^{1}\\\\\n", "P_{t}^{2}\\\\\n", "e_{1,t}+\\theta_{t}\\\\\n", "e_{2,t}+\\theta_{t}\\\\\n", "e_{1,t}\\\\\n", "e_{2,t}\n", "\\end{array}\\right]}_{y_{t}} & = \\underbrace{\\left[\\begin{array}{cccccccc}\n", "0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\\\\n", "0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\\\\n", "1 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\\\\n", "0 & 1 & 0 & 0 & 0 & 0 & 1 & 0\\\\\n", "1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n", "0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\n", "\\end{array}\\right]}_{G}\\underbrace{\\left[\\begin{array}{c}\n", "e_{1,t}\\\\\n", "e_{2,t}\\\\\n", "k_{t}^{i}\\\\\n", "\\tilde{\\theta}_{t}\\\\\n", "P_{t}^{1}\\\\\n", "P_{t}^{2}\\\\\n", "\\theta_{t}\\\\\n", "v_{t}\n", "\\end{array}\\right]}_{x_{t}}+\\underbrace{\\left[\\begin{array}{c}\n", "0\\\\\n", "0\\\\\n", "0\\\\\n", "0\\\\\n", "0\\\\\n", "0\n", "\\end{array}\\right]}_{H}w_{t+1}\\\\\n", "\\left[\\begin{array}{c}\n", "z_{1,t+1}\\\\\n", "z_{2,t+1}\\\\\n", "z_{3,t+1}\\\\\n", "w_{t+1}\n", "\\end{array}\\right] & \\sim \\mathcal{N}\\left(0,I\\right)\\\\\n", "\\kappa & = \\frac{\\rho p}{2p+\\sigma_{e}^{2}}\n", "\\end{aligned}\n", "$$" ] }, { "cell_type": "code", "execution_count": null, "id": "3f10aede", "metadata": { "hide-output": false }, "outputs": [], "source": [ "A_ricc = np.array([[ρ]])\n", "B_ricc = np.array([[np.sqrt(2)]])\n", "R_ricc = np.array([[σ_e ** 2]])\n", "Q_ricc = np.array([[σ_v ** 2]])\n", "N_ricc = np.zeros((1, 1))\n", "p = qe.solve_discrete_riccati(A_ricc, B_ricc, Q_ricc, R_ricc, N_ricc).item()\n", "\n", "p_two = p # Save for comparison later" ] }, { "cell_type": "code", "execution_count": null, "id": "ed05a1e0", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Verify that p = σ_v^2 + (pρ^2σ_e^2) / (2p + σ_e^2)\n", "tol = 1e-12\n", "np.abs(p - (σ_v ** 2 + p * ρ ** 2 * σ_e ** 2 / (2 * p + σ_e ** 2))) < tol" ] }, { "cell_type": "code", "execution_count": null, "id": "78289fda", "metadata": { "hide-output": false }, "outputs": [], "source": [ "κ = ρ * p / (2 * p + σ_e ** 2)\n", "κ_prod = κ * σ_e ** 2 / p\n", "\n", "κ_two = κ # Save for comparison later\n", "\n", "A_lss = np.array([[0., 0., 0., 0., 0., 0., 0., 0.],\n", " [0., 0., 0., 0., 0., 0., 0., 0.],\n", " [κ / (λ - ρ), κ / (λ - ρ), λ_tilde, -κ_prod / (λ - ρ), 0., 0., ρ / (λ - ρ), 0.],\n", " [-κ, -κ, 0., κ_prod, 0., 0., 0., 1.],\n", " [b * κ / (λ - ρ), b * κ / (λ - ρ), b * λ_tilde, -b * κ_prod / (λ - ρ), 0., 0., b * ρ / (λ - ρ) + ρ, 1.],\n", " [b * κ / (λ - ρ), b * κ / (λ - ρ), b * λ_tilde, -b * κ_prod / (λ - ρ), 0., 0., b * ρ / (λ - ρ) + ρ, 1.],\n", " [0., 0., 0., 0., 0., 0., ρ, 1.],\n", " [0., 0., 0., 0., 0., 0., 0., 0.]])\n", "\n", "C_lss = np.array([[σ_e, 0., 0.],\n", " [0., σ_e, 0.],\n", " [0., 0., 0.],\n", " [0., 0., 0.],\n", " [σ_e, 0., 0.],\n", " [0., σ_e, 0.],\n", " [0., 0., 0.],\n", " [0., 0., σ_v]])\n", "\n", "G_lss = np.array([[0., 0., 0., 0., 1., 0., 0., 0.],\n", " [0., 0, 0, 0., 0., 1., 0., 0.],\n", " [1., 0., 0., 0., 0., 0., 1., 0.],\n", " [0., 1., 0., 0., 0., 0., 1., 0.],\n", " [1., 0., 0., 0., 0., 0., 0., 0.],\n", " [0., 1., 0., 0., 0., 0., 0., 0.]])" ] }, { "cell_type": "code", "execution_count": null, "id": "c9eafff9", "metadata": { "hide-output": false }, "outputs": [], "source": [ "mu_0 = np.array([0., 0., 0., 0., 0., 0., 0., 0.])\n", "\n", "lss = qe.LinearStateSpace(A_lss, C_lss, G_lss, mu_0=mu_0)" ] }, { "cell_type": "code", "execution_count": null, "id": "6794a758", "metadata": { "hide-output": false }, "outputs": [], "source": [ "ts_length = 100_000\n", "x, y = lss.simulate(ts_length, random_state=1)" ] }, { "cell_type": "code", "execution_count": null, "id": "eafcfe67", "metadata": { "hide-output": false }, "outputs": [], "source": [ "xcoef, ycoef = lss.impulse_response(j=20)" ] }, { "cell_type": "code", "execution_count": null, "id": "f326a9b1", "metadata": { "hide-output": false }, "outputs": [], "source": [ "data = np.array([xcoef])[0, :, 2, :]\n", "\n", "fig = go.Figure(data=go.Scatter(y=data[:-1, 0], name=r'$e_{1,t+1}$'))\n", "fig.add_trace(go.Scatter(y=data[:-1, 1], name=r'$e_{2,t+1}$'))\n", "fig.add_trace(go.Scatter(y=data[1:, 2], name=r'$v_{t+1}$'))\n", "fig.update_layout(title=r'Impulse Response Function',\n", " xaxis_title='Time',\n", " yaxis_title=r'$k^{i}_{t}$')\n", "fig2=fig\n", "# Export to PNG file\n", "Image(fig2.to_image(format=\"png\"))\n", "# fig2.show() will provide interactive plot when running\n", "# notebook locally" ] }, { "cell_type": "code", "execution_count": null, "id": "738fb912", "metadata": { "hide-output": false }, "outputs": [], "source": [ "_, _, Σ_x, Σ_y, Σ_yx = lss.stationary_distributions()\n", "\n", "Σ_11 = Σ_x[1, 1]\n", "Σ_12 = Σ_x[1, 2:5]\n", "Σ_21 = Σ_x[2:5, 1]\n", "Σ_22 = Σ_x[2:5, 2:5]\n", "\n", "reg_coeffs = Σ_12 @ np.linalg.inv(Σ_22)\n", "\n", "print('Regression coefficients (e_{2,t} on k_t, P^{1}_t, \\\\tilde{\\\\theta_t})')\n", "print('------------------------------')\n", "print(r'k_t:', reg_coeffs[0])\n", "print(r'\\tilde{\\theta_t}:', reg_coeffs[1])\n", "print(r'P_t:', reg_coeffs[2])" ] }, { "cell_type": "code", "execution_count": null, "id": "7c8fc293", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Compute R squared\n", "R_squared = reg_coeffs @ Σ_x[2:5, 2:5] @ reg_coeffs / Σ_x[1, 1]\n", "R_squared" ] }, { "cell_type": "code", "execution_count": null, "id": "9c23800a", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Verify that the computed coefficients are close to least squares estimates\n", "model = OLS(x[1], x[2:5].T)\n", "reg_res = model.fit()\n", "np.max(np.abs(reg_coeffs - reg_res.params)) < 1e-2" ] }, { "cell_type": "code", "execution_count": null, "id": "25f07cb9", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Verify that R_squared matches least squares estimate\n", "np.abs(reg_res.rsquared - R_squared) < 1e-2" ] }, { "cell_type": "code", "execution_count": null, "id": "5c5cf1dd", "metadata": { "hide-output": false }, "outputs": [], "source": [ "_, _, Σ_x, Σ_y, Σ_yx = lss.stationary_distributions()\n", "\n", "Σ_11 = Σ_x[1, 1]\n", "Σ_12 = Σ_x[1, 2:6]\n", "Σ_21 = Σ_x[2:6, 1]\n", "Σ_22 = Σ_x[2:6, 2:6]\n", "\n", "reg_coeffs = Σ_12 @ np.linalg.inv(Σ_22)\n", "\n", "print('Regression coefficients (e_{2,t} on k_t, P^{1}_t, P^{2}_t, \\\\tilde{\\\\theta_t})')\n", "print('------------------------------')\n", "print(r'k_t:', reg_coeffs[0])\n", "print(r'\\tilde{\\theta_t}:', reg_coeffs[1])\n", "print(r'P^{1}_t:', reg_coeffs[2])\n", "print(r'P^{2}_t:', reg_coeffs[3])" ] }, { "cell_type": "code", "execution_count": null, "id": "b7914bac", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Compute R squared\n", "R_squared = reg_coeffs @ Σ_x[2:6, 2:6] @ reg_coeffs / Σ_x[1, 1]\n", "R_squared" ] }, { "cell_type": "markdown", "id": "9e52b3d5", "metadata": {}, "source": [ "## Key Step\n", "\n", "Now we come to the key step for verifying that equilibrium outcomes for prices and quantities are identical\n", "in the pooling equilibrium original model that led Townsend to deduce an infinite-dimensional state space.\n", "\n", "We accomplish this by computing a population linear least squares regression of the noisy signal that firms in the other\n", "industry receive in a pooling equilibrium on time $ t $ information that a firm would receive in Townsend’s\n", "original model.\n", "\n", "Let’s compute the regression and stare at the $ R^2 $:" ] }, { "cell_type": "code", "execution_count": null, "id": "8e7baefe", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Verify that θ_t + e^{2}_t can be recovered\n", "\n", "# θ_t + e^{2}_t on k^{i}_t, P^{1}_t, P^{2}_t, \\\\tilde{\\\\theta_t}\n", "\n", "\n", "model = OLS(y[1], x[2:6].T)\n", "reg_res = model.fit()\n", "np.abs(reg_res.rsquared - 1.) < 1e-6" ] }, { "cell_type": "code", "execution_count": null, "id": "ba7742e2", "metadata": { "hide-output": false }, "outputs": [], "source": [ "reg_res.rsquared" ] }, { "cell_type": "markdown", "id": "70f8b633", "metadata": {}, "source": [ "The $ R^2 $ in this regression equals $ 1 $.\n", "\n", "That verifies that a firm’s information\n", "set in Townsend’s original model equals its information set in a pooling equilibrium.\n", "\n", "Therefore, equilibrium prices and quantities in Townsend’s original model equal those in a pooling equilibrium." ] }, { "cell_type": "markdown", "id": "e6a102b0", "metadata": {}, "source": [ "## An observed common shock benchmark\n", "\n", "For purposes of comparison, it is useful to construct a model in which demand disturbance in both industries\n", "still both share have a common persistent component $ \\theta_t $, but in which the persistent component $ \\theta $ is observed each period.\n", "\n", "In this case, firms share the same information immediately and have no need to deploy signal-extraction techniques.\n", "\n", "Thus, consider a version of our model in which histories of both $ \\epsilon_t^i $ and $ \\theta_t $ are observed by a representative firm.\n", "\n", "In this case, the firm’s optimal decision rule is described by\n", "\n", "$$\n", "k_{t+1}^i = \\tilde \\lambda k_t^i + \\frac{1}{\\lambda - \\rho} \\hat \\theta_{t+1}\n", "$$\n", "\n", "where $ \\hat \\theta_{t+1} = E_t \\theta_{t+1} $ is given by\n", "\n", "$$\n", "\\hat \\theta_{t+1} = \\rho \\theta_t\n", "$$\n", "\n", "Thus, the firm’s decision rule can be expressed\n", "\n", "$$\n", "k_{t+1}^i = \\tilde \\lambda k_t^i + \\frac{\\rho}{\\lambda - \\rho} \\theta_t\n", "$$\n", "\n", "Consequently, when a history $ \\theta_s, s \\leq t $ is observed without noise,\n", "the following state space system prevails:\n", "\n", "$$\n", "\\begin{aligned}\n", "\\begin{bmatrix} \\theta_{t+1} \\cr k_{t+1}^i \\end{bmatrix} & =\n", "\\begin{bmatrix} \\rho & 0 \\cr\n", " \\frac{\\rho}{\\lambda -\\rho} & \\tilde \\lambda \\end{bmatrix}\n", " \\begin{bmatrix} \\theta_t \\cr k_t^i \\end{bmatrix}\n", " + \\begin{bmatrix} \\sigma_v \\cr 0 \\end{bmatrix} z_{1,t+1} \\cr\n", "\\begin{bmatrix} \\theta_t \\cr k_t^i \\end{bmatrix} & = \\begin{bmatrix} 1 & 0 \\cr 0 & 1 \\end{bmatrix}\n", "\\begin{bmatrix} \\theta_t \\cr k_t^i \\end{bmatrix} +\n", "\\begin{bmatrix} 0 \\cr 0 \\end{bmatrix} z_{1,t+1}\n", "\\end{aligned}\n", "$$\n", "\n", "where $ z_{t,t+1} $ is a scalar iid standardized Gaussian process.\n", "\n", "As usual, the system can be written as\n", "\n", "$$\n", "\\begin{aligned}\n", "x_{t+1} & = A x_t + C z_{t+1} \\cr\n", "y_t & = G x_t + H w_{t+1}\n", "\\end{aligned}\n", "$$\n", "\n", "In order once again to use the quantecon class `quantecon.LinearStateSpace`, let’s form pertinent state-space matrices" ] }, { "cell_type": "code", "execution_count": null, "id": "8b477193", "metadata": { "hide-output": false }, "outputs": [], "source": [ "Ao_lss = np.array([[ρ, 0.],\n", " [ρ / (λ - ρ), λ_tilde]])\n", "\n", "Co_lss = np.array([[σ_v], [0.]])\n", "\n", "Go_lss = np.identity(2)" ] }, { "cell_type": "code", "execution_count": null, "id": "be81fff7", "metadata": { "hide-output": false }, "outputs": [], "source": [ "muo_0 = np.array([0., 0.])\n", "\n", "lsso = qe.LinearStateSpace(Ao_lss, Co_lss, Go_lss, mu_0=muo_0)" ] }, { "cell_type": "markdown", "id": "5f6fc3a8", "metadata": {}, "source": [ "Now let’s form and plot an impulse response function of $ k_t^i $ to shocks $ v_t $ to $ \\theta_{t+1} $" ] }, { "cell_type": "code", "execution_count": null, "id": "8283f7f8", "metadata": { "hide-output": false }, "outputs": [], "source": [ "xcoef, ycoef = lsso.impulse_response(j=21)\n", "data = np.array([ycoef])[0, :, 1, :]\n", "\n", "fig = go.Figure(data=go.Scatter(y=data[:-1, 0], name=r'$z_{t+1}$'))\n", "fig.update_layout(title=r'Impulse Response Function',\n", " xaxis_title= r'lag $j$',\n", " yaxis_title=r'$k^{i}_{t}$')\n", "fig3 = fig\n", "# Export to PNG file\n", "Image(fig3.to_image(format=\"png\"))\n", "# fig1.show() will provide interactive plot when running\n", "# notebook locally" ] }, { "cell_type": "markdown", "id": "24af1a6e", "metadata": {}, "source": [ "## Comparison of All Signal Structures\n", "\n", "It is enlightening side by side to plot impulse response functions for capital for the two\n", "noisy-signal information structures and the noiseless signal on $ \\theta $ that we have just presented.\n", "\n", "Please remember that the two-signal structure corresponds to the **pooling equilibrium** and also\n", "**Townsend’s original model**." ] }, { "cell_type": "code", "execution_count": null, "id": "38603ec6", "metadata": { "hide-output": false }, "outputs": [], "source": [ "fig_comb = go.Figure(data=[\n", " *fig1.data,\n", " *fig2.update_traces(xaxis='x2', yaxis='y2').data,\n", " *fig3.update_traces(xaxis='x3', yaxis='y3').data\n", " ]).set_subplots(1, 3,\n", " subplot_titles=(\"One noisy-signal\",\n", " \"Two noisy-signal\",\n", " \"No Noise\"),\n", " horizontal_spacing=0.02,\n", " shared_yaxes=True)\n", "# Export to PNG file\n", "Image(fig_comb.to_image(format=\"png\"))\n", "# fig_comb.show() # will provide interactive plot when running\n", "# notebook locally" ] }, { "cell_type": "markdown", "id": "3b1c22b4", "metadata": {}, "source": [ "The three panels in the graph above show that\n", "\n", "- responses of $ k_t^i $ to shocks $ v_t $ to the hidden Markov demand state $ \\theta_t $ process are **largest** in the no-noisy-signal structure in which the firm observes $ \\theta_t $ at time $ t $ \n", "- responses of $ k_t^i $ to shocks $ v_t $ to the hidden Markov demand state $ \\theta_t $ process are **smaller** in the two-noisy-signal structure \n", "- responses of $ k_t^i $ to shocks $ v_t $ to the hidden Markov demand state $ \\theta_t $ process are **smallest** in the one-noisy-signal structure \n", "\n", "\n", "With respect to the iid demand shocks $ e_t $ the graphs show that\n", "\n", "- responses of $ k_t^i $ to shocks $ e_t $ to the hidden Markov demand state $ \\theta_t $ process are **smallest** (i.e., nonexistent) in the no-noisy-signal structure in which the firm observes $ \\theta_t $ at time $ t $ \n", "- responses of $ k_t^i $ to shocks $ e_t $ to the hidden Markov demand state $ \\theta_t $ process are **larger** in the two-noisy-signal structure \n", "- responses of $ k_t^i $ to idiosyncratic *own-market* noise-shocks $ e_t $ are **largest** in the one-noisy-signal structure \n", "\n", "\n", "Among other things, these findings indicate that time series correlations and coherences between outputs in the two industries are higher in the two-noisy-signals or **pooling** model than they are in the one-noisy signal model.\n", "\n", "The enhanced influence of the shocks $ v_t $ to the hidden Markov demand state $ \\theta_t $ process that\n", "emerges from the two-noisy-signal model relative to the one-noisy-signal model is a symptom of a lower\n", "equilibrium hidden-state reconstruction error variance in the two-signal model:" ] }, { "cell_type": "code", "execution_count": null, "id": "b3bc5f62", "metadata": { "hide-output": false }, "outputs": [], "source": [ "display(Latex('$\\\\textbf{Reconstruction error variances}$'))\n", "display(Latex(f'One-noise structure: {round(p_one, 6)}'))\n", "display(Latex(f'Two-noise structure: {round(p_two, 6)}'))" ] }, { "cell_type": "markdown", "id": "6e42d3f0", "metadata": {}, "source": [ "Kalman gains for the two\n", "structures are" ] }, { "cell_type": "code", "execution_count": null, "id": "e69e6ea3", "metadata": { "hide-output": false }, "outputs": [], "source": [ "display(Latex('$\\\\textbf{Kalman Gains}$'))\n", "display(Latex(f'One noisy-signal structure: {round(κ_one, 6)}'))\n", "display(Latex(f'Two noisy-signals structure: {round(κ_two, 6)}'))" ] }, { "cell_type": "markdown", "id": "3e356194", "metadata": {}, "source": [ "Another lesson that comes from the preceding three-panel graph is that the presence of iid noise\n", "$ \\epsilon_t^i $ in industry $ i $ generates a response in $ k_t^{-i} $ in the two-noisy-signal structure, but not in the one-noisy-signal structure." ] }, { "cell_type": "markdown", "id": "c56d209e", "metadata": {}, "source": [ "## Notes on History of the Problem\n", "\n", "To truncate what he saw as an intractable, infinite dimensional state space,\n", "Townsend constructed an approximating model in which the common hidden Markov demand shock\n", "is revealed to all firms after a fixed number of periods.\n", "\n", "Thus,\n", "\n", "- Townsend wanted to assume that at time $ t $ firms in industry $ i $ observe\n", " $ k_t^i, Y_t^i, P_t^i, (P^{-i})^t $, where $ (P^{-i})^t $ is the history of prices in\n", " the other market up to time $ t $. \n", "- Because that turned out to be too challenging, Townsend made a sensible\n", " alternative assumption that eased his calculations: that after a large\n", " number $ S $ of periods, firms in industry $ i $ observe the\n", " hidden Markov component of the demand shock $ \\theta_{t-S} $. \n", "\n", "\n", "Townsend argued that the more manageable model could do a good job of\n", "approximating the intractable model in which the Markov component of the demand shock remains unobserved\n", "for ever.\n", "\n", "By applying technical machinery of [[PCL86](https://python-advanced.quantecon.org/zreferences.html#id23)], [[PS05](https://python-advanced.quantecon.org/zreferences.html#id22)] showed that there is a recursive\n", "representation of the equilibrium of the perpetually and symmetrically\n", "uninformed model that Townsend wanted to solve\n", "[[Tow83](https://python-advanced.quantecon.org/zreferences.html#id25)].\n", "\n", "A reader of [[PS05](https://python-advanced.quantecon.org/zreferences.html#id22)] will notice that their representation of the equilibrium of\n", "Townsend’s model exactly matches that of the **pooling equilibrium** presented here.\n", "\n", "We have structured our notation in this lecture to faciliate comparison of the **pooling equilibrium**\n", "constructed here with the equilibrium of Townsend’s model reported in [[PS05](https://python-advanced.quantecon.org/zreferences.html#id22)].\n", "\n", "The computational method of [[PS05](https://python-advanced.quantecon.org/zreferences.html#id22)] is recursive:\n", "it enlists the Kalman filter and invariant subspace methods for\n", "solving systems of Euler\n", "equations [5] .\n", "\n", "As [[Sin87](https://python-advanced.quantecon.org/zreferences.html#id27)], [[Kas00](https://python-advanced.quantecon.org/zreferences.html#id24)], and [[Sar91](https://python-advanced.quantecon.org/zreferences.html#id26)] also\n", "found, the equilibrium is fully revealing: observed prices tell\n", "participants in industry $ i $ all of the information held by\n", "participants in market $ -i $ ($ -i $ means not $ i $).\n", "\n", "This\n", "means that higher-order beliefs play no role: observing equilibrium prices\n", "in effect lets decision makers pool their information\n", "sets [6] .\n", "\n", "The disappearance of higher order beliefs means that\n", "decision makers in this model do not really face a problem of\n", "forecasting the forecasts of others.\n", "\n", "Because\n", "those forecasts are the same as their own, they know them." ] }, { "cell_type": "markdown", "id": "0f779057", "metadata": {}, "source": [ "### Further historical remarks\n", "\n", "Sargent [[Sar91](https://python-advanced.quantecon.org/zreferences.html#id26)] proposed a way to compute an equilibrium\n", "without making Townsend’s approximation.\n", "\n", "Extending the reasoning of [[Mut60](https://python-advanced.quantecon.org/zreferences.html#id110)], Sargent noticed that it is possible to\n", "summarize the relevant history with a low dimensional object, namely, a\n", "small number of current and lagged forecasting errors.\n", "\n", "Positing an\n", "equilibrium in a space of perceived laws of motion for endogenous\n", "variables that takes the form of a vector autoregressive, moving\n", "average, Sargent described an equilibrium as a fixed point of a mapping\n", "from the perceived law of motion to the actual law of motion of that\n", "form.\n", "\n", "Sargent worked in the time domain and proceeded to guess and verify the\n", "appropriate orders of the autoregressive and moving average pieces of\n", "the equilibrium representation.\n", "\n", "By working in the frequency\n", "domain [[Kas00](https://python-advanced.quantecon.org/zreferences.html#id24)] showed how to discover the appropriate\n", "orders of the autoregressive and moving average parts, and also how to\n", "compute an equilibrium.\n", "\n", "The [[PS05](https://python-advanced.quantecon.org/zreferences.html#id22)] recursive computational method, which stays in the time domain, also\n", "discovered appropriate orders of the autoregressive and moving\n", "average pieces.\n", "\n", "In addition, by displaying equilibrium representations\n", "in the form of [[PCL86](https://python-advanced.quantecon.org/zreferences.html#id23)], [[PS05](https://python-advanced.quantecon.org/zreferences.html#id22)]\n", "showed how the moving average piece is linked to the innovation process\n", "of the hidden persistent component of the demand shock.\n", "\n", "That scalar\n", "innovation process is the additional state variable contributed by the\n", "problem of extracting a signal from equilibrium prices that decision\n", "makers face in Townsend’s model.\n", "\n", "
[1] [[PS05](https://python-advanced.quantecon.org/zreferences.html#id22)] verified this assertion using a different tactic, namely, by constructing\n", "analytic formulas for an equilibrium under the incomplete\n", "information structure and confirming that they match the pooling equilibrium formulas derived here.\n", "\n", "
[2] See [[Sar87](https://python-advanced.quantecon.org/zreferences.html#id197)], especially\n", "chapters IX and XIV, for principles that guide solving some roots backwards and others forwards.\n", "\n", "
[3] As noted by [[Sar87](https://python-advanced.quantecon.org/zreferences.html#id197)], this difference equation is the Euler equation for\n", "a planning problem that maximizes the discounted sum of consumer plus\n", "producer surplus.\n", "\n", "
[4] [[PS05](https://python-advanced.quantecon.org/zreferences.html#id22)] verify the same claim by applying machinery of [[PCL86](https://python-advanced.quantecon.org/zreferences.html#id23)].\n", "\n", "
[5] See [[AHMS96](https://python-advanced.quantecon.org/zreferences.html#id135)] for an account of invariant subspace methods.\n", "\n", "
[6] See [[AMS02](https://python-advanced.quantecon.org/zreferences.html#id28)] for a discussion\n", "of information assumptions needed to create a situation\n", "in which higher order beliefs appear in equilibrium decision rules. A way\n", "to read our findings in light of [[AMS02](https://python-advanced.quantecon.org/zreferences.html#id28)] is that, relative\n", "to the number of signals agents observe, Townsend’s\n", "section 8 model has too few random shocks to get higher order beliefs to\n", "play a role." ] } ], "metadata": { "date": 1705369586.4425664, "filename": "knowing_forecasts_of_others.md", "kernelspec": { "display_name": "Python", "language": "python3", "name": "python3" }, "title": "Knowing the Forecasts of Others" }, "nbformat": 4, "nbformat_minor": 5 }