diff --git a/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb b/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb index b3fc9024..79485662 100644 --- a/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb +++ b/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb @@ -6,7 +6,37 @@ "source": [ "# A Gentle Introduction to Buffer Stock Saving \n", "\n", - "This notebook explores the behavior of a consumer identical to the perfect foresight consumer described in [Gentle-Intro-To-HARK-PerfForesightCRRA](https://econ-ark.org/materials/Gentle-Intro-To-HARK-PerfForesightCRRA) except that now the model incorporates income uncertainty.\n", + "This notebook explores the behavior of a consumer identical to the perfect foresight consumer described in [Gentle-Intro-To-HARK-PerfForesightCRRA](https://econ-ark.org/materials/Gentle-Intro-To-HARK-PerfForesightCRRA) except that now the model incorporates income uncertainty." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "code_folding": [] + }, + "outputs": [], + "source": [ + "# This cell has just a bit of initial setup. You can click the triangle to the left to expand it.\n", + "# Click the \"Run\" button immediately above the notebook in order to execute the contents of any cell\n", + "# WARNING: Each cell in the notebook relies upon results generated by previous cells\n", + "# The most common problem beginners have is to execute a cell before all its predecessors\n", + "# If you do this, you can restart the kernel (see the \"Kernel\" menu above) and start over\n", + "import matplotlib.pyplot as plt\n", + "\n", + "import numpy as np\n", + "import HARK \n", + "from time import clock\n", + "from copy import deepcopy\n", + "mystr = lambda number : \"{:.4f}\".format(number)\n", + "from HARK.utilities import plotFuncs" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Changes to the model\n", "\n", "Specifically, our new type of consumer receives two income shocks at the beginning of each period: a completely transitory shock $\\theta_t$ and a completely permanent shock $\\psi_t$. Moreover, lenders set a limit on borrowing: The ratio of end-of-period assets $A_t$ to permanent income $P_t$ must be less greater than $\\underline{a} \\leq 0$. As with the perfect foresight problem, this model can be framed in terms of _normalized_ variables, e.g. $m_t \\equiv M_t/P_t$. (See [here](http://econ.jhu.edu/people/ccarroll/papers/BufferStockTheory/) for all the theory).\n", "\n", @@ -17,25 +47,13 @@ "m_{t+1} &=& R/(\\Gamma_{t+1} \\psi_{t+1}) a_t + \\theta_{t+1}, \\\\\n", "(\\psi_t,\\theta_t) \\sim F_{t}, &\\qquad& \\mathbb{E} [F_{\\psi t}] = [F_{\\theta t}] = 1, \\\\\n", "U(c) &=& \\frac{c^{1-\\rho}}{1-\\rho}.\n", - "\\end{eqnarray*}\n", - "\n", - "HARK represents agents with this kind of problem as instances of the class $\\texttt{IndShockConsumerType}$. To create a $\\texttt{IndShockConsumerType}$ instance, we must specify the same set of parameters as for a $\\texttt{PerfForesightConsumerType}$, as well as an artificial borrowing constraint $\\underline{a}$ and a sequence of income shock distributions $\\{F_t\\}$. It's easy enough to pick a borrowing constraint-- say, $\\underline{a} = 0$ so that the consumer cannot borrow at all.\n", - "\n", - "Computers are discrete devices; even if somehow we knew with certainty that the distributions of the transitory and permanent shocks were, say, continuously lognormally distributed, in order to be represented on a computer those distributions would need to be approximated by a finite and discrete set of points. A large literature in numerical computation explores ways to construct such approximations; probably the easiest example to understand is the equiprobable approximation, in which the continuous distribution is represented by a set of $N$ outcomes that are equally likely to occur. \n", - "\n", - "In the case of a single variable (say, the permanent shock $\\psi$), and when the number of equiprobable points is, say, 5, the procedure is to construct a list: $psi_{0}$ is the mean value of the continuous $\\psi$ given that the draw of $\\psi$ is in the bottom 20 percent of the distribution of the continuous $\\psi$. $\\\\psi_{1}$ is the mean value of $\\psi$ given that the draw is between the 20th and 40th percentiles, and so on. The expectation of some expression $f(\\psi)$ can be very quickly calculated by:\n", - "\n", - "$$ \n", - "\\mathbb{E}_{t}[f(\\psi)] \\approx (1/N) \\sum_{i=0}^{N-1} f(\\psi_{i})\n", - "$$" + "\\end{eqnarray*}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "In principle, any smooth multivariate continuous distribution can be approximated to an arbitrary degree of accuracy with a fine enough matrix of points and their corresponding probailities. This is, in fact, the fundamental way that HARK represents uncertainty: By a specifying a multidimensional array containing joint probabilities of the realizations of the shocks.\n", - "\n", "The simplest assumption (and therefore the default choice in $\\texttt{IndShockConsumerType}$) is that the transitory and permanent shocks are independent. The permanent shock is assumed to be lognormal, while the transitory shock has two components: A probability $\\wp$ that the consumer is unemployed, in which case $\\theta=\\underline{\\theta}$, and a probability $(1-\\wp)$ of a shock that is a lognormal with a mean chosen so that $\\mathbb{E}_{t}[\\theta_{t+n}]=1$.\n", "\n", "The $\\texttt{IndShockConsumerType}$ inherits all of the parameters of the original $\\texttt{PerfForesightConsumerType}$ class. Given the assumptions above, we need to specify the extra parameters to specify the income shock distribution and the artificial borrowing constraint. As before, we'll make a dictionary:\n", @@ -53,31 +71,15 @@ ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": { - "code_folding": [] - }, - "outputs": [], + "cell_type": "markdown", + "metadata": {}, "source": [ - "# This cell has just a bit of initial setup. You can click the triangle to the left to expand it.\n", - "# Click the \"Run\" button immediately above the notebook in order to execute the contents of any cell\n", - "# WARNING: Each cell in the notebook relies upon results generated by previous cells\n", - "# The most common problem beginners have is to execute a cell before all its predecessors\n", - "# If you do this, you can restart the kernel (see the \"Kernel\" menu above) and start over\n", - "%matplotlib inline\n", - "import matplotlib.pyplot as plt\n", - "\n", - "import numpy as np\n", - "import HARK \n", - "from copy import deepcopy\n", - "mystr = lambda number : \"{:.4f}\".format(number)\n", - "from HARK.utilities import plotFuncs" + "HARK represents agents with this kind of problem as instances of the class $\\texttt{IndShockConsumerType}$. To create a $\\texttt{IndShockConsumerType}$ instance, we only need to define an artificial borrowing constraint $\\underline{a}$ and a sequence of income shock distributions $\\{F_t\\}$. It's easy enough to pick a borrowing constraint-- say, $\\underline{a} = 0$ so that the consumer cannot borrow at all." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "code_folding": [ 0, @@ -89,11 +91,6 @@ "# This cell defines a parameter dictionary for making an instance of IndShockConsumerType.\n", "\n", "IndShockDictionary = {\n", - " 'CRRA': 2.5, # The dictionary includes our original parameters...\n", - " 'Rfree': 1.03,\n", - " 'DiscFac': 0.96,\n", - " 'LivPrb': [0.98],\n", - " 'PermGroFac': [1.01],\n", " 'PermShkStd': [0.1], # ... and the new parameters for constructing the income process. \n", " 'PermShkCount': 7,\n", " 'TranShkStd': [0.1],\n", @@ -101,26 +98,8 @@ " 'UnempPrb': 0.05,\n", " 'IncUnemp': 0.3,\n", " 'BoroCnstArt': 0.0,\n", - " 'aXtraMin': 0.001, # aXtra parameters specify how to construct the grid of assets.\n", - " 'aXtraMax': 50., # Don't worry about these for now\n", - " 'aXtraNestFac': 3,\n", - " 'aXtraCount': 48,\n", - " 'aXtraExtra': [None],\n", - " 'vFuncBool': False, # These booleans indicate whether the value function should be calculated\n", - " 'CubicBool': False, # and whether to use cubic spline interpolation. You can ignore them.\n", - " 'aNrmInitMean' : -10.,\n", - " 'aNrmInitStd' : 0.0, # These parameters specify the (log) distribution of normalized assets\n", - " 'pLvlInitMean' : 0.0, # and permanent income for agents at \"birth\". They are only relevant in\n", - " 'pLvlInitStd' : 0.0, # simulation and you don't need to worry about them.\n", - " 'PermGroFacAgg' : 1.0,\n", - " 'T_retire': 0, # What's this about retirement? ConsIndShock is set up to be able to\n", - " 'UnempPrbRet': 0.0, # handle lifecycle models as well as infinite horizon problems. Swapping\n", - " 'IncUnempRet': 0.0, # out the structure of the income process is easy, but ignore for now.\n", - " 'T_age' : None,\n", - " 'T_cycle' : 1,\n", - " 'cycles' : 0,\n", - " 'AgentCount': 10000,\n", - " 'tax_rate':0.0,\n", + " \n", + " 'cycles' : 0 # infinite time horizon -- see below\n", "}\n", " \n", "# Hey, there's a lot of parameters we didn't tell you about! Yes, but you don't need to\n", @@ -131,19 +110,404 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "As before, we need to import the relevant subclass of $\\texttt{AgentType}$ into our workspace, then create an instance by passing the dictionary to the class as if the class were a function." + "Though we can override them if we like, it's simpler to use default values provided by HARK. The `PerfForesightConsumerType` class has many of these attributes already.\n", + "\n", + "You can see all the **attributes** of an object in Python by using the `dir()` command. You can see that many of the model variables are now attributes of this object, along with many other attributes that are outside the scope of this tutorial." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['AgentCount',\n", + " 'BoroCnstArt',\n", + " 'CRRA',\n", + " 'DiscFac',\n", + " 'LivPrb',\n", + " 'MaxKinks',\n", + " 'PermGroFac',\n", + " 'PermGroFacAgg',\n", + " 'RNG',\n", + " 'Rfree',\n", + " 'T_age',\n", + " 'T_cycle',\n", + " '__call__',\n", + " '__class__',\n", + " '__delattr__',\n", + " '__dict__',\n", + " '__dir__',\n", + " '__doc__',\n", + " '__eq__',\n", + " '__format__',\n", + " '__ge__',\n", + " '__getattribute__',\n", + " '__gt__',\n", + " '__hash__',\n", + " '__init__',\n", + " '__init_subclass__',\n", + " '__le__',\n", + " '__lt__',\n", + " '__module__',\n", + " '__ne__',\n", + " '__new__',\n", + " '__reduce__',\n", + " '__reduce_ex__',\n", + " '__repr__',\n", + " '__setattr__',\n", + " '__sizeof__',\n", + " '__str__',\n", + " '__subclasshook__',\n", + " '__weakref__',\n", + " 'aNrmInitMean',\n", + " 'aNrmInitStd',\n", + " 'addToTimeInv',\n", + " 'addToTimeVary',\n", + " 'assignParameters',\n", + " 'cFunc_terminal_',\n", + " 'checkConditions',\n", + " 'checkElementsOfTimeVaryAreLists',\n", + " 'checkRestrictions',\n", + " 'clearHistory',\n", + " 'cycles',\n", + " 'delFromTimeInv',\n", + " 'delFromTimeVary',\n", + " 'distance',\n", + " 'getAvg',\n", + " 'getControls',\n", + " 'getMortality',\n", + " 'getPostStates',\n", + " 'getRfree',\n", + " 'getShocks',\n", + " 'getStates',\n", + " 'initializeSim',\n", + " 'makeShockHistory',\n", + " 'pLvlInitMean',\n", + " 'pLvlInitStd',\n", + " 'postSolve',\n", + " 'poststate_vars',\n", + " 'poststate_vars_',\n", + " 'preSolve',\n", + " 'pseudo_terminal',\n", + " 'quiet',\n", + " 'readShocks',\n", + " 'read_shocks',\n", + " 'resetRNG',\n", + " 'seed',\n", + " 'shock_vars',\n", + " 'shock_vars_',\n", + " 'simBirth',\n", + " 'simDeath',\n", + " 'simOnePeriod',\n", + " 'simulate',\n", + " 'solution_terminal',\n", + " 'solution_terminal_',\n", + " 'solve',\n", + " 'solveOnePeriod',\n", + " 'timeFlip',\n", + " 'timeFwd',\n", + " 'timeReport',\n", + " 'timeRev',\n", + " 'time_flow',\n", + " 'time_inv',\n", + " 'time_inv_',\n", + " 'time_vary',\n", + " 'time_vary_',\n", + " 'tolerance',\n", + " 'track_vars',\n", + " 'unpackcFunc',\n", + " 'updateSolutionTerminal',\n", + " 'vFunc_terminal_',\n", + " 'verbose']" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType\n", + "\n", + "pfc = PerfForesightConsumerType()\n", + "dir(pfc)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`IndShockConsumerType` is a **superclass** of `PerfForesightConsumerType`. This means that it builds on the functionality of the other type. You can find the superclasses of a type in Python using the `__bases__` attribute." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(HARK.ConsumptionSaving.ConsIndShockModel.PerfForesightConsumerType,)" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType\n", + "\n", + "IndShockConsumerType.__bases__" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ "IndShockExample = IndShockConsumerType(**IndShockDictionary)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As before, we need to import the relevant subclass of $\\texttt{AgentType}$ into our workspace, then create an instance by passing the dictionary to the class as if the class were a function." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Discretizing probability distributions\n", + "\n", + "Computers are discrete devices; even if somehow we knew with certainty that the distributions of the transitory and permanent shocks were, say, continuously lognormally distributed, in order to be represented on a computer those distributions would need to be approximated by a finite and discrete set of points. A large literature in numerical computation explores ways to construct such approximations; probably the easiest example to understand is the equiprobable approximation, in which the continuous distribution is represented by a set of $N$ outcomes that are equally likely to occur. \n", + "\n", + "In the case of a single variable (say, the permanent shock $\\psi$), and when the number of equiprobable points is, say, 5, the procedure is to construct a list: $psi_{0}$ is the mean value of the continuous $\\psi$ given that the draw of $\\psi$ is in the bottom 20 percent of the distribution of the continuous $\\psi$. $\\\\psi_{1}$ is the mean value of $\\psi$ given that the draw is between the 20th and 40th percentiles, and so on. The expectation of some expression $f(\\psi)$ can be very quickly calculated by:\n", + "\n", + "$$ \n", + "\\mathbb{E}_{t}[f(\\psi)] \\approx (1/N) \\sum_{i=0}^{N-1} f(\\psi_{i})\n", + "$$\n", + "\n", + "In principle, any smooth multivariate continuous distribution can be approximated to an arbitrary degree of accuracy with a fine enough matrix of points and their corresponding probailities. This is, in fact, the fundamental way that HARK represents uncertainty: By a specifying a multidimensional array containing joint probabilities of the realizations of the shocks." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The scatterplot below shows how the discretized probability distribution is represented in HARK. The lognormal distribution is represented by a set of equiprobable point masses." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEGCAYAAABy53LJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAYbElEQVR4nO3de5QmdX3n8feHk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TmBXCupzLKv+VeSfLIJI/eMc/g52PSJ7PmzXz3zvd1YnD76R8ZXDH8YdN2AXBCM78c+F8M7r9fB7ysaf8NYH3Tdg3wqp7VfTLw3eY7HwV2H9r2d4CNzfSGvtcMPB9Y1/wdrAPOmuNz/RkGtybvZXDv/CzgHOCcZn2AC5vjWgeM9eBcP6iaF8C5fmLT/jPg9mZ+r6l+vvpcM4MnwK5vpvVzWfOok0OOSJJa8VaVJKkVg0OS1IrBIUlqxeCQJLVicEiSWjE4pFmQwUjJx05o+4MkH55mmzu7r0yafQaHNDs+w+CXy4ad2rRLDysGhzQ7Pge8ovntZJIcBDwZuDaDd4lc07xfYaeRWZP8WpIvDi1/KMmZzfxhzWCZa5Os7sNItZLBIc2CqvoJ8A8MBqWDwdXGZcBdwKtrMGDdi4H3Jsko+0yyK/BB4OSqOozBUCvvmO3apbYeMd8FSA8jO25XfaH5PIvBEB5/3Ixuej+DIb2fAPzTCPt7OvCrwFearFnCYAgLaV4ZHNLs+QLwvuZ1q79SVWubW05LgcOq6t4kmxkMiDlsOw+8+t+xPsD6qjqq27KldrxVJc2SqrqTwRsKP84vO8UfA/ywCY0XAwdOsukPgOVJdk+yN82oy8AGYGmSo2Bw6yrJszo9CGkEXnFIs+szDN6fsOMJq08Df5NkHTAOfGfiBlV1S5LLGAyd/X3g2qb9niQnAx9I8hgG/17fz2DEVGneODquJKkVb1VJkloxOCRJrRgckqRWDA5JUisGhySpFYNDktSKwSFJauX/AxSZgMTw4Q3LAAAAAElFTkSuQmCC\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.scatter(IndShockExample.PermShkDstn[0][1],\n", + " IndShockExample.PermShkDstn[0][0])\n", + "plt.xlabel(\"Value\")\n", + "plt.ylabel(\"Probability Mass\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Notice that this distribution was created when the `IndShockConsumerType` object was initialized, but it was not an attribute you gave it directly." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Backwards Induction\n", + "\n", + "HARK will solve this problem using _backwards induction_.\n", + "\n", + "It will derive a solution for each period ($t$) by choosing the optimal policy mapping from market resources $m$ to consumption $c$. This function will be stored in a variable named `cFunc`.\n", + "\n", + "Backwards induction requires a \"terminal\" (last, final) period to work backwards from. Our `IndShockExample` has been initialized with a terminal solution. There are many functions wrapped together in the solution object, which is of type `ConsumerSolution`." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "IndShockExample.solution_terminal" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The consumption function `cFunc` is define by _linear interpolation_.\n", + "It is defined by a series of $(x,y)$ points on a grid; the value of the function for any $x$ is the $y$ determined by the line between the nearest defined gridpoints.\n", + "You can see below that in the terminal period, $c = m$; the agent consumes all available resources." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAZ2ElEQVR4nO3de3RV9Zn/8fcDKNL5qTgDrQhSsNI2aUHAiPprrSBSKGsWWLzP6qhtkqMizm/VC2Dpal1OqwEqXYoXCBcpVosICGlFuSQg1iWXyCUIikR0hgRaEYIzA1RCeX5/nEPmEBNyEs7JOXufz2st1jp77+/KfrYJjw/77E+OuTsiIhJ8bdJdgIiIJIcauohISKihi4iEh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L7b95XTXneLrLQbujr3OBT5Od92ncb3fA/oD7zZyfDjwGmDAFcC6ZJ4/KBP6AKDS3Xe5+1FgHjCy3pqRwO9irxcAg+3EJ0gHT5PX6+6r3P1wbHMt0Q/vDqJEvrcA/w5MBP7WmsWlQCLXWwg87e41AO7+SSvXmEyJXK8D58RenwvsacX6ksrd1xD9GM7GjATmetRaoKOZdUnW+YPS0LsCu+O2q2L7Glzj7seAz4B/apXqki+R642XT/T/+kHU5LXG/ll6obu/2pqFpUgi39uvA183s7fMbK2ZDWu16pIvket9GPiRmVUR/ajLe1untLRo7t/tZknoM0Ulc5nZj4A84Op015IKZtYGmALckeZSWlM7orddBhL9l9caM+vt7gfTWlXq3ArMcffHzexKoh84/213P57uwoImKBN6NXBh3Ha32L4G15hZO6L/dNvfKtUlXyLXi5ldC0wARrj7561UW7I1da1nA98GVpvZx0TvO5YE+I3RRL63VUCJu9e6+0fAB0QbfBAlcr35wHwAd38bOIvoL7IKo4T+brdUUBr6BqCXmfU0szOJvulZUm9NCXB77PUNQJnH3oUIoCav18z6AdOJNvMg32M95bW6+2fu3snde7h7D6LvF4xw9/L0lHvaEvlZXkx0OsfMOhG9BbOrNYtMokSu9z+BwQBmlkO0oe9r1SpbTwlwW+xplyuAz9x9b9K+errfFW7Gu8fDiU4qHwITYvseIfqXG6I/BC8DlcB64KJ015zi610J/BXYHPtTku6aU3Wt9dauJsBPuST4vTWit5m2A1uBW9Jdc4qvNxd4i+gTMJuB76e75tO41j8Ae4Faov/SygfuAu6K+94+HftvsTXZP8uK/ouIhERQbrmIiEgT1NBFREJCDV1EJCTU0EVEQkINXUQkJNTQRURCQg1dRCQk/j/IEcCcUO9WDQAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.plot(IndShockExample.solution_terminal.cFunc.x_list,\n", + " IndShockExample.solution_terminal.cFunc.y_list,\n", + " color='k')\n", + "plt.scatter(IndShockExample.solution_terminal.cFunc.x_list,\n", + " IndShockExample.solution_terminal.cFunc.y_list)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The solution also has a representation of a `value function`, the value `v(m)` as a function of available market resources. Because the agent consumes all their resources in the last period, the value function for the terminal solution looks just like the CRRA utility function." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/sb/projects/econ-ark/HARK/HARK/utilities.py:141: RuntimeWarning: divide by zero encountered in reciprocal\n", + " return( c**(1.0 - gam) / (1.0 - gam) )\n" + ] + }, + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAD4CAYAAADhNOGaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAe1ElEQVR4nO3deZScdZ3v8fe39zXd6XRnp7MTNjFAG8KoLAGVyYwijCAgiApEHfGe48ydKx7mzPXO1TtXR8dzdFAJEXFUBJeJMIKiLIp6SSBsIQFCd0K2TtLVSaeTrt6r6nv/qEooku5OJ9VVT3c9n9c5derZqp5v1en+fep5nt/zPObuiIhIeBUEXYCIiARLQSAiEnIKAhGRkFMQiIiEnIJARCTkioIu4GTU19f73Llzgy5DRGRCee655/a5e8PR0ydkEMydO5f169cHXYaIyIRiZtuHmq5dQyIiIacgEBEJOQWBiEjIKQhEREJOQSAiEnIKAhGRkFMQiIiE3IQ8j0BEZCJLJJz+WIK+wTh9sTi9A3H6BhP0xeLJaYOp8bTn3sE4/YNxrjp3NnPrK8e0HgWBiEgad2cgnqCnP07PYJye/hjdA4cb6zg9A8lGuXcwTu9AjN6BBL2Dh+fF6B1M0D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a0yWA8BH031HloGHHT3PSf7Zto1NM64e8zMbgMeJdl74h5332Rm/wysd/eHgH8FqoCfmRnADnf/QGBFj7FRfgd5a5Sf/1HgvWb2ChAH/sHd9wdX9dgZ5ef/e+BuM/scyQPHH/NUd5p8YGY/IRn09anjIP8TKAZw9++SPC6yAmgBeoCPZ7S+PPruRETkJGjXkIhIyCkIRERCTkEgIhJyCgIRkZBTEIiIhJyCQEQk5BQEIiIh9/8Bi170v3RCTv8AAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "x = np.linspace(0,1,20)\n", + "plt.plot(x,\n", + " IndShockExample.solution_terminal.vFunc(x))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If these are the consumption and value functions for the _last_ period, what are the functions for the _first_ period?\n", + "\n", + "Recall that we are solving this problem on the _infinite time horizon_; in other words, there is no \"first period\"." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "IndShockExample.cycles" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "What we will do instead is perform backwards induction until the consumption and value functions _converge_. We will see that this derived consumption function looks quite different from the terminal solution." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Solving the problem" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -153,14 +517,77 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD6CAYAAACoCZCsAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhc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": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], "source": [ "IndShockExample.solve()\n", "plotFuncs(IndShockExample.solution[0].cFunc,0.,10.)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This solution was generated by running a **method** that is an attribute of the `IndShockExample` object. Many methods in Python have a description, called its **documentation**, that will tell you what it does and what its arguments are. You can read the documentation for methods and other attributes in HARK with the built-in Python `help()` function." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on method solve in module HARK.core:\n", + "\n", + "solve(verbose=False) method of HARK.ConsumptionSaving.ConsIndShockModel.IndShockConsumerType instance\n", + " Solve the model for this instance of an agent type by backward induction.\n", + " Loops through the sequence of one period problems, passing the solution\n", + " from period t+1 to the problem for period t.\n", + " \n", + " Parameters\n", + " ----------\n", + " verbose : boolean\n", + " If True, solution progress is printed to screen.\n", + " \n", + " Returns\n", + " -------\n", + " none\n", + "\n" + ] + } + ], + "source": [ + "help(IndShockExample.solve)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -176,9 +603,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "\n", + "\n", + "\n" + ] + } + ], "source": [ "OtherExample = deepcopy(IndShockExample) # Make a copy so we can compare consumption functions\n", "OtherExample.PermShkStd = [0.2] # Double permanent income risk (note that it's a one element list)\n", @@ -195,7 +634,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "code_folding": [], "lines_to_next_cell": 2 @@ -211,9 +650,9 @@ "formats": "ipynb,py:percent" }, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3.7 econ-ark", "language": "python", - "name": "python3" + "name": "econ-ark" }, "language_info": { "codemirror_mode": { @@ -225,7 +664,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.7.5" } }, "nbformat": 4, diff --git a/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.py b/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.py index 215d920e..b0bad846 100644 --- a/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.py +++ b/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.py @@ -6,17 +6,35 @@ # extension: .py # format_name: percent # format_version: '1.2' -# jupytext_version: 1.2.3 +# jupytext_version: 1.2.4 # kernelspec: -# display_name: Python 3 +# display_name: Python 3.7 econ-ark # language: python -# name: python3 +# name: econ-ark # --- # %% [markdown] # # A Gentle Introduction to Buffer Stock Saving # # This notebook explores the behavior of a consumer identical to the perfect foresight consumer described in [Gentle-Intro-To-HARK-PerfForesightCRRA](https://econ-ark.org/materials/Gentle-Intro-To-HARK-PerfForesightCRRA) except that now the model incorporates income uncertainty. + +# %% {"code_folding": []} +# This cell has just a bit of initial setup. You can click the triangle to the left to expand it. +# Click the "Run" button immediately above the notebook in order to execute the contents of any cell +# WARNING: Each cell in the notebook relies upon results generated by previous cells +# The most common problem beginners have is to execute a cell before all its predecessors +# If you do this, you can restart the kernel (see the "Kernel" menu above) and start over +import matplotlib.pyplot as plt + +import numpy as np +import HARK +from time import clock +from copy import deepcopy +mystr = lambda number : "{:.4f}".format(number) +from HARK.utilities import plotFuncs + +# %% [markdown] +# ## Changes to the model # # Specifically, our new type of consumer receives two income shocks at the beginning of each period: a completely transitory shock $\theta_t$ and a completely permanent shock $\psi_t$. Moreover, lenders set a limit on borrowing: The ratio of end-of-period assets $A_t$ to permanent income $P_t$ must be less greater than $\underline{a} \leq 0$. As with the perfect foresight problem, this model can be framed in terms of _normalized_ variables, e.g. $m_t \equiv M_t/P_t$. (See [here](http://econ.jhu.edu/people/ccarroll/papers/BufferStockTheory/) for all the theory). # @@ -28,20 +46,8 @@ # (\psi_t,\theta_t) \sim F_{t}, &\qquad& \mathbb{E} [F_{\psi t}] = [F_{\theta t}] = 1, \\ # U(c) &=& \frac{c^{1-\rho}}{1-\rho}. # \end{eqnarray*} -# -# HARK represents agents with this kind of problem as instances of the class $\texttt{IndShockConsumerType}$. To create a $\texttt{IndShockConsumerType}$ instance, we must specify the same set of parameters as for a $\texttt{PerfForesightConsumerType}$, as well as an artificial borrowing constraint $\underline{a}$ and a sequence of income shock distributions $\{F_t\}$. It's easy enough to pick a borrowing constraint-- say, $\underline{a} = 0$ so that the consumer cannot borrow at all. -# -# Computers are discrete devices; even if somehow we knew with certainty that the distributions of the transitory and permanent shocks were, say, continuously lognormally distributed, in order to be represented on a computer those distributions would need to be approximated by a finite and discrete set of points. A large literature in numerical computation explores ways to construct such approximations; probably the easiest example to understand is the equiprobable approximation, in which the continuous distribution is represented by a set of $N$ outcomes that are equally likely to occur. -# -# In the case of a single variable (say, the permanent shock $\psi$), and when the number of equiprobable points is, say, 5, the procedure is to construct a list: $psi_{0}$ is the mean value of the continuous $\psi$ given that the draw of $\psi$ is in the bottom 20 percent of the distribution of the continuous $\psi$. $\\psi_{1}$ is the mean value of $\psi$ given that the draw is between the 20th and 40th percentiles, and so on. The expectation of some expression $f(\psi)$ can be very quickly calculated by: -# -# $$ -# \mathbb{E}_{t}[f(\psi)] \approx (1/N) \sum_{i=0}^{N-1} f(\psi_{i}) -# $$ # %% [markdown] -# In principle, any smooth multivariate continuous distribution can be approximated to an arbitrary degree of accuracy with a fine enough matrix of points and their corresponding probailities. This is, in fact, the fundamental way that HARK represents uncertainty: By a specifying a multidimensional array containing joint probabilities of the realizations of the shocks. -# # The simplest assumption (and therefore the default choice in $\texttt{IndShockConsumerType}$) is that the transitory and permanent shocks are independent. The permanent shock is assumed to be lognormal, while the transitory shock has two components: A probability $\wp$ that the consumer is unemployed, in which case $\theta=\underline{\theta}$, and a probability $(1-\wp)$ of a shock that is a lognormal with a mean chosen so that $\mathbb{E}_{t}[\theta_{t+n}]=1$. # # The $\texttt{IndShockConsumerType}$ inherits all of the parameters of the original $\texttt{PerfForesightConsumerType}$ class. Given the assumptions above, we need to specify the extra parameters to specify the income shock distribution and the artificial borrowing constraint. As before, we'll make a dictionary: @@ -57,30 +63,13 @@ # | $\mho$ | Unemployment probability | $\texttt{UnempPrb}$ | 0.05 | # | $\underline{\theta}$ | Transitory shock when unemployed | $\texttt{IncUnemp}$ | 0.3 | -# %% {"code_folding": []} -# This cell has just a bit of initial setup. You can click the triangle to the left to expand it. -# Click the "Run" button immediately above the notebook in order to execute the contents of any cell -# WARNING: Each cell in the notebook relies upon results generated by previous cells -# The most common problem beginners have is to execute a cell before all its predecessors -# If you do this, you can restart the kernel (see the "Kernel" menu above) and start over -# %matplotlib inline -import matplotlib.pyplot as plt - -import numpy as np -import HARK -from copy import deepcopy -mystr = lambda number : "{:.4f}".format(number) -from HARK.utilities import plotFuncs +# %% [markdown] +# HARK represents agents with this kind of problem as instances of the class $\texttt{IndShockConsumerType}$. To create a $\texttt{IndShockConsumerType}$ instance, we only need to define an artificial borrowing constraint $\underline{a}$ and a sequence of income shock distributions $\{F_t\}$. It's easy enough to pick a borrowing constraint-- say, $\underline{a} = 0$ so that the consumer cannot borrow at all. # %% {"code_folding": [0, 2]} # This cell defines a parameter dictionary for making an instance of IndShockConsumerType. IndShockDictionary = { - 'CRRA': 2.5, # The dictionary includes our original parameters... - 'Rfree': 1.03, - 'DiscFac': 0.96, - 'LivPrb': [0.98], - 'PermGroFac': [1.01], 'PermShkStd': [0.1], # ... and the new parameters for constructing the income process. 'PermShkCount': 7, 'TranShkStd': [0.1], @@ -88,38 +77,110 @@ 'UnempPrb': 0.05, 'IncUnemp': 0.3, 'BoroCnstArt': 0.0, - 'aXtraMin': 0.001, # aXtra parameters specify how to construct the grid of assets. - 'aXtraMax': 50., # Don't worry about these for now - 'aXtraNestFac': 3, - 'aXtraCount': 48, - 'aXtraExtra': [None], - 'vFuncBool': False, # These booleans indicate whether the value function should be calculated - 'CubicBool': False, # and whether to use cubic spline interpolation. You can ignore them. - 'aNrmInitMean' : -10., - 'aNrmInitStd' : 0.0, # These parameters specify the (log) distribution of normalized assets - 'pLvlInitMean' : 0.0, # and permanent income for agents at "birth". They are only relevant in - 'pLvlInitStd' : 0.0, # simulation and you don't need to worry about them. - 'PermGroFacAgg' : 1.0, - 'T_retire': 0, # What's this about retirement? ConsIndShock is set up to be able to - 'UnempPrbRet': 0.0, # handle lifecycle models as well as infinite horizon problems. Swapping - 'IncUnempRet': 0.0, # out the structure of the income process is easy, but ignore for now. - 'T_age' : None, - 'T_cycle' : 1, - 'cycles' : 0, - 'AgentCount': 10000, - 'tax_rate':0.0, + + 'cycles' : 0 # infinite time horizon -- see below } # Hey, there's a lot of parameters we didn't tell you about! Yes, but you don't need to # think about them for now. # %% [markdown] -# As before, we need to import the relevant subclass of $\texttt{AgentType}$ into our workspace, then create an instance by passing the dictionary to the class as if the class were a function. +# Though we can override them if we like, it's simpler to use default values provided by HARK. The `PerfForesightConsumerType` class has many of these attributes already. +# +# You can see all the **attributes** of an object in Python by using the `dir()` command. You can see that many of the model variables are now attributes of this object, along with many other attributes that are outside the scope of this tutorial. + +# %% +from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType + +pfc = PerfForesightConsumerType() +dir(pfc) + +# %% [markdown] +# `IndShockConsumerType` is a **superclass** of `PerfForesightConsumerType`. This means that it builds on the functionality of the other type. You can find the superclasses of a type in Python using the `__bases__` attribute. # %% from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType + +IndShockConsumerType.__bases__ + +# %% IndShockExample = IndShockConsumerType(**IndShockDictionary) +# %% [markdown] +# As before, we need to import the relevant subclass of $\texttt{AgentType}$ into our workspace, then create an instance by passing the dictionary to the class as if the class were a function. + +# %% [markdown] +# ## Discretizing probability distributions +# +# Computers are discrete devices; even if somehow we knew with certainty that the distributions of the transitory and permanent shocks were, say, continuously lognormally distributed, in order to be represented on a computer those distributions would need to be approximated by a finite and discrete set of points. A large literature in numerical computation explores ways to construct such approximations; probably the easiest example to understand is the equiprobable approximation, in which the continuous distribution is represented by a set of $N$ outcomes that are equally likely to occur. +# +# In the case of a single variable (say, the permanent shock $\psi$), and when the number of equiprobable points is, say, 5, the procedure is to construct a list: $psi_{0}$ is the mean value of the continuous $\psi$ given that the draw of $\psi$ is in the bottom 20 percent of the distribution of the continuous $\psi$. $\\psi_{1}$ is the mean value of $\psi$ given that the draw is between the 20th and 40th percentiles, and so on. The expectation of some expression $f(\psi)$ can be very quickly calculated by: +# +# $$ +# \mathbb{E}_{t}[f(\psi)] \approx (1/N) \sum_{i=0}^{N-1} f(\psi_{i}) +# $$ +# +# In principle, any smooth multivariate continuous distribution can be approximated to an arbitrary degree of accuracy with a fine enough matrix of points and their corresponding probailities. This is, in fact, the fundamental way that HARK represents uncertainty: By a specifying a multidimensional array containing joint probabilities of the realizations of the shocks. + +# %% [markdown] +# The scatterplot below shows how the discretized probability distribution is represented in HARK. The lognormal distribution is represented by a set of equiprobable point masses. + +# %% +plt.scatter(IndShockExample.PermShkDstn[0][1], + IndShockExample.PermShkDstn[0][0]) +plt.xlabel("Value") +plt.ylabel("Probability Mass") +plt.show() + +# %% [markdown] +# Notice that this distribution was created when the `IndShockConsumerType` object was initialized, but it was not an attribute you gave it directly. + +# %% [markdown] +# ## Backwards Induction +# +# HARK will solve this problem using _backwards induction_. +# +# It will derive a solution for each period ($t$) by choosing the optimal policy mapping from market resources $m$ to consumption $c$. This function will be stored in a variable named `cFunc`. +# +# Backwards induction requires a "terminal" (last, final) period to work backwards from. Our `IndShockExample` has been initialized with a terminal solution. There are many functions wrapped together in the solution object, which is of type `ConsumerSolution`. + +# %% +IndShockExample.solution_terminal + +# %% [markdown] +# The consumption function `cFunc` is define by _linear interpolation_. +# It is defined by a series of $(x,y)$ points on a grid; the value of the function for any $x$ is the $y$ determined by the line between the nearest defined gridpoints. +# You can see below that in the terminal period, $c = m$; the agent consumes all available resources. + +# %% +plt.plot(IndShockExample.solution_terminal.cFunc.x_list, + IndShockExample.solution_terminal.cFunc.y_list, + color='k') +plt.scatter(IndShockExample.solution_terminal.cFunc.x_list, + IndShockExample.solution_terminal.cFunc.y_list) + +# %% [markdown] +# The solution also has a representation of a `value function`, the value `v(m)` as a function of available market resources. Because the agent consumes all their resources in the last period, the value function for the terminal solution looks just like the CRRA utility function. + +# %% +x = np.linspace(0,1,20) +plt.plot(x, + IndShockExample.solution_terminal.vFunc(x)) + +# %% [markdown] +# If these are the consumption and value functions for the _last_ period, what are the functions for the _first_ period? +# +# Recall that we are solving this problem on the _infinite time horizon_; in other words, there is no "first period". + +# %% +IndShockExample.cycles + +# %% [markdown] +# What we will do instead is perform backwards induction until the consumption and value functions _converge_. We will see that this derived consumption function looks quite different from the terminal solution. + +# %% [markdown] +# ## Solving the problem + # %% [markdown] # Now we can solve our new agent's problem just like before, using the $\texttt{solve}$ method. @@ -127,6 +188,12 @@ IndShockExample.solve() plotFuncs(IndShockExample.solution[0].cFunc,0.,10.) +# %% [markdown] +# This solution was generated by running a **method** that is an attribute of the `IndShockExample` object. Many methods in Python have a description, called its **documentation**, that will tell you what it does and what its arguments are. You can read the documentation for methods and other attributes in HARK with the built-in Python `help()` function. + +# %% +help(IndShockExample.solve) + # %% [markdown] # ## Changing Constructed Attributes #