diff --git a/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb b/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb index ca79171e..baba1ae0 100644 --- a/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb +++ b/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb @@ -6,7 +6,38 @@ "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", + "%matplotlib inline\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", @@ -19,23 +50,13 @@ "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", - "$$" + "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." ] }, { "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", @@ -54,31 +75,7 @@ }, { "cell_type": "code", - "execution_count": null, - "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", - "%matplotlib inline\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": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "code_folding": [ 0, @@ -90,11 +87,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", @@ -102,32 +94,22 @@ " '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", " \n", "# Hey, there's a lot of parameters we didn't tell you about! Yes, but you don't need to\n", "# think about them for now." ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType\n", + "IndShockExample = IndShockConsumerType(**IndShockDictionary)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -135,14 +117,61 @@ "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": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEGCAYAAABy53LJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAYbElEQVR4nO3de5QmdX3n8feHkVtUBGW8MdxUVh2zrkiDoILRjQJeAA0kKEQwbFjCspusB4/jZj1ng5roq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8YdN2AXBCM78c+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": [ - "from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType\n", - "IndShockExample = IndShockConsumerType(**IndShockDictionary)" + "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": [ + "## Solving the problem" ] }, { @@ -154,9 +183,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAeDklEQVR4nO3deXiU5b3/8fcdsgdIgLBDCEsWdggBETdkEahbracigktdqL+2bnVve+qvp1URUVFREVGr4lKrVlsl7Ii4sIoLkJUlYU9CIAmBbDP3+SPpEamaSZzJM5P5vK7LixBnHj4+V+bjwzPfuW9jrUVERAJPiNMBRESkaVTgIiIBSgUuIhKgVOAiIgFKBS4iEqBCfXHQ+Ph4m5iY6ItDi4i0SJs3by621nZszHN8UuCJiYls2rTJF4cWEWmRjDH5jX2ObqGIiAQoFbiISIBSgYuIBCgVuIhIgFKBi4gEKBW4iEiAUoGLiAQoFbiIiMPyCo816Xk++SCPiIg07FBZJXNX5PDmpr1Ner4KXESkmZVV1vDsmh08//EuXG7LlaN78acmHEcFLiLSTKpqXbzyWT7zVudx9HgNPx3Wjd9OTCGhQ7QKXETEH7nclve+2Mcjy3LYd/QEZyXFc/fkVAZ1j/1Rx1WBi4j4iLWWNTlFzMrIIutgOYO6t+WhS4dwZlK8V46vAhcR8YEv9xxlVkYWn+08TEL7aJ6cNpzzB3clJMR47c9QgYuIeNGu4grmLM3mg68P0CEmnD9dNJBpoxIID/X+1LYKXETECwrLK3liZS5vbNhDeGgIt4xP4oaz+9A6wnc1qwIXEfkRyitreO6jnTy3dhc1LjdXnJbATeOS6Ngmwud/tgpcRKQJqmvdvLY+nydX5XG4opoLhnTljvNSSIyPabYMKnARkUZwuy3/+mo/jyzLoaDkOGP6duCeKakM6RHX7FlU4CIiHlqbWzcSuG1/Gf27tuWla0dxdlI8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MJUjPiTGmO3AzkG6tHUTdUtWXO5uqWf0VmHzK9+4BVlprk4CV9b//Qd68Am/05sctlbX2gLX28/qvy6l7kf7HPqLBwhjTAzgfWOh0FicZY2KBs4HnAay11dbao86mclQoEGWMCQWigf0O52k21tqPgJJTvn0x8FL91y8BP23oON4scI82Pw42xphEYDiw3tkkjpoL3AW4nQ7isN5AEfBi/e2khcaYGKdDOcFauw+YAxQAB4BSa+0yZ1M5rrO19kD91weBzg09QW9i+pAxpjXwNnCrtbbM6TxOMMZcABRaazc7ncUPhAJpwDPW2uFABR78Nbklqr+/ezF1/1PrBsQYY2Y4m8p/2Lr57gZnvL1Z4Nr8+CTGmDDqyvtVa+07Tudx0BnARcaY3dTdVhtnjFnkbCTH7AX2Wmv//bext6gr9GA0AdhlrS2y1tYA7wBjHM7ktEPGmK4A9b8WNvQEbxa4Nj+uZ4wx1N3nzLTWPup0HidZa++11vaw1iZS9zOxyloblFda1tqDwB5jTEr9t8YD2x2M5KQCYLQxJrr+9TKeIH1D9yT/BK6u//pq4L2GnuC11Qi1+fG3nAFcCXxtjPmi/nu/q99bVILbTcCr9Rc5O4FfOJzHEdba9caYt4DPqZva2kIQfazeGPM6MBaIN8bsBe4DZgFvGmOuA/KByxo8jj5KLyISmPQmpohIgFKBi4gEKBW4iEiAUoGLiAQoFbiISIBSgYuIBCgVuIhIgPpfJx/qUwih2LkAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], "source": [ "IndShockExample.solve()\n", "plotFuncs(IndShockExample.solution[0].cFunc,0.,10.)" @@ -177,7 +219,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -196,7 +238,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "code_folding": [], "lines_to_next_cell": 2 @@ -212,9 +254,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": { @@ -226,7 +268,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 af36c1f0..950c3fd2 100644 --- a/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.py +++ b/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.py @@ -6,17 +6,36 @@ # extension: .py # format_name: percent # format_version: '1.2' -# jupytext_version: 1.2.1 +# 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 +# %matplotlib inline +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). # @@ -30,18 +49,8 @@ # \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,31 +66,10 @@ # | $\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 time import clock -from copy import deepcopy -mystr = lambda number : "{:.4f}".format(number) -from HARK.utilities import plotFuncs - # %% {"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], @@ -89,37 +77,43 @@ '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, } # 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. +# %% +from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType +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. + # %% -from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType -IndShockExample = IndShockConsumerType(**IndShockDictionary) +plt.scatter(IndShockExample.PermShkDstn[0][1], + IndShockExample.PermShkDstn[0][0]) +plt.xlabel("Value") +plt.ylabel("Probability Mass") +plt.show() + +# %% [markdown] +# ## Solving the problem # %% [markdown] # Now we can solve our new agent's problem just like before, using the $\texttt{solve}$ method.