{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Make graphs appear within the notebook\n", "%matplotlib inline\n", "\n", "# Import numerical computations library\n", "import numpy as np\n", "\n", "# Import plotting library\n", "import matplotlib.pyplot as plt\n", "\n", "# Import functions from MacroPlots.py\n", "from MacroPlots import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Intertemporal choice of a consumer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us talk first on how to model the choice of a consumer,\n", "whose life is divided in two time periods: $t$ and $t+1$. \n", "\n", "If it helps you in building your intuition, imagine that the first time period ($t$) represents the period when the agent is young and working, while the second time period ($t+1$) represents the period when the agent is old and retired.\n", "\n", "I have also picked a specific functional form for the utility function: the logarithmic function. The reason for this choice is that the logarithmic function has a super easy derivative:\n", "\n", "\\begin{align}\n", "\\frac{\\partial \\ln x}{\\partial x} = \\frac{1}{x}\n", "\\end{align}\n", "\n", "and this will simplify our calculations quite a lot." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Utility maximization problem\n", "\n", "Our aim is to construct an optimization problem, the solution to which will closely approximate the choices of actual people.\n", "\n", "Imagine that our consumer earns income $y_{t}$ in the first period, and income $y_{t+1}$ in the second period. \n", "\n", "Moreover the consumer can either save a part of the first period income, or borrow against second period income. For simplicity, the real interest rate for saving and borrowing is the same and is denoted with $r$.\n", "\n", "The consumer is also impatient, in the sense that she prefers to consume today rather than in the future (although she does not want to starve in the future!). We capture this feature of human behavior by assuming that future outcomes are discounted with the discount factor $0\\leq\\beta\\leq 1$.\n", "\n", "Formally, we set up a maximization problem, constrained by the consumer's budget constraint:\n", "\n", "\\begin{align}\n", "\\max_{c_{t}, c_{t+1}} \\quad & U=\\ln c_{t}+\\beta\\ln c_{t+1}\\\\\n", "\\text{subject to} \\quad & c_{t}+\\frac{c_{t+1}}{1+r}\\leq y_{t}+\\frac{y_{t+1}}{1+r}\n", "\\end{align}\n", "\n", "where the constraint implies that the present dicounted value (PDV) of lifetime consumption cannot exceed the PDV of lifetime income.\n", "\n", "Let us first plot the budget set: the set of all attainable consumption bundles given our endowments: incomes in period $t$ and $t+1$, which we will denote in `python codes` as period 0 and 1." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the graph below, the point $(y_{t}, y_{t+1})$ denotes the initial endowment of consumer's incomes. \n", "\n", "Thanks to the ability to save or borrow, the consumer can choose at maximum the amount $y_{t}+y_{t+1}/(1+r)$ in the first period (and consume 0 in the second period) or save the entire first period income and consume $(1+r)\\cdot y_{t}+y_{t+1}$ in the second period (and consume 0 in the first period).\n", "\n", "All three mentioned points lie on the same budget line. The budget set contains also some points where the PDV of consumption is smaller than the PDV of income, but in this context choosing any point that does not lie on the budget line would not be optimal." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "y_0 = 2\n", "y_1 = 1\n", "r = 0.05\n", "β = 0.95\n", "\n", "PlotBudgetSet(y_0, y_1, r, full_labels=True)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The graph below depicts a so-called indifference map, that is, a set of indifference curves, corresponding to allocations between which the consumer is indifferent. Indifference curves that lie to the northeast represent higher levels of utility." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "PlotIndifferenceCurves(y_0, y_1, β, r, levels=[0, 0.5, 1, 1.5], full_labels=True)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The graph below shows the budget set and two indifference curves. The green indifference curve is infeasible -- there are no points in the budget set that lie on this curve. The yellow indifference curve is feasible -- there are points in the budget set that lie on this curve -- but is clearly not optimal, as we could find some points in the budget set that lie to the northeast of the yellow indifference curve.\n", "\n", "Graphically, optimal choice involves choosing such a point from the budget set that lies on the highest possible indifference curve, such that this surve is tangent to the budget line.\n", "\n", "You can attempt to find an (approximate) graphical solution by appending a number to the `levels=[0.5, 1]` list in the code below." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# This will make both plots appear in the same figure\n", "fig, ax = plt.subplots(figsize=(5, 5))\n", "\n", "PlotBudgetSet(y_0, y_1, r, fig_ax=(fig, ax))\n", "PlotIndifferenceCurves(y_0, y_1, β, levels=[0.5, 1], fig_ax=(fig, ax))\n", "\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The code below solves the Utility Maximization Problem of the consumer and displays the results.\n", "\n", "If you want, you can change the parameters of the problem, for example to see when the consumer is a saver, and when a borrower (although be aware that for crazy parameters you can get crazy outcomes)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "y_0 = 2\n", "y_1 = 1\n", "r = 0.05\n", "β = 0.95\n", "\n", "SolveUtilityMaximizationProblem(y_0, y_1, β, r)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that in the above graph there appears an **Euler equation** curve. You will find an explanation below.\n", "\n", "### Solving UMP with the Lagrange method\n", "\n", "Although in principle the UMP could be solved with a variety of methods, we will solve it with the Lagrange method. The advantage of this method is that it scales well to problems with a large (or even infinite) number of variables involved.\n", "\n", "Recall our problem:\n", "\n", "\\begin{align}\n", "\\max\\quad & U=\\ln c_{t}+\\beta\\ln c_{t+1}\\\\\n", "\\text{subject to}\\quad & c_{t}+\\frac{c_{t+1}}{1+r}\\leq y_{t}+\\frac{y_{t+1}}{1+r}\n", "\\end{align}\n", "\n", "Rewrite the budget constraint in the form of $0\\leq\\ldots$:\n", "\n", "\\begin{align}\n", "0\\leq y_{t}+\\frac{y_{t+1}}{1+r}-c_{t}-\\frac{c_{t+1}}{1+r}\n", "\\end{align}\n", "\n", "And set up a Lagrange function:\n", "\n", "\\begin{align}\n", "\\mathcal{L}=\\ln c_{t}+\\beta\\ln c_{t+1}+\\lambda\\left[y_{t}+\\frac{y_{t+1}}{1+r}-c_{t}-\\frac{c_{t+1}}{1+r}\\right]\n", "\\end{align}\n", "\n", "where $\\lambda$ is called the Lagrange multiplier. Next we derive the First Order Conditions (FOCs), that is, calculate the derivatives of the Lagrangian with respect to the choice variables. In this problem there are two choice variables -- $c_{t}$ and $c_{t+1}$:\n", "\n", "\\begin{align}\n", "\\frac{\\partial\\mathcal{L}}{\\partial c_{t}} & =\\frac{1}{c_{t}}+\\lambda\\left[-1\\right]=0\\\\\n", "\\frac{\\partial\\mathcal{L}}{\\partial c_{t+1}} & =\\beta\\cdot\\frac{1}{c_{t+1}}+\\lambda\\left[-\\frac{1}{1+r}\\right]=0\n", "\\end{align}\n", "\n", "Let us simplify the above equations:\n", "\n", "\\begin{align}\n", "\\lambda & =\\frac{1}{c_{t}}\\\\\n", "\\lambda & =\\beta\\left(1+r\\right)\\frac{1}{c_{t+1}}\n", "\\end{align}\n", "\n", "\n", "And combine them:\n", "\n", "\\begin{align}\n", "\\frac{1}{c_{t}} & =\\beta\\left(1+r\\right)\\frac{1}{c_{t+1}}\\\\\n", "c_{t+1} & =\\beta\\left(1+r\\right)c_{t}\n", "\\end{align}\n", "\n", "The resulting equation is called the intertemporal condition (from Latin: across time) or the [Euler equation](https://www.econjobrumors.com/topic/why-is-it-called-euler-equation).\n", "\n", "At this stage, the Lagrangian procedure has allowed us to restate our problem, involving finding a point on a curve tangent to a line, to the problem of finding an intersection of two curves: the budget constraint and the Euler equation, which is much simpler to solve:\n", "\n", "\\begin{align}\n", "\\begin{cases}\n", "c_{t}+\\dfrac{c_{t+1}}{1+r}=y_{t}+\\dfrac{y_{t+1}}{1+r}\\\\\n", "c_{t+1}=\\beta\\left(1+r\\right)c_{t}\n", "\\end{cases}\n", "\\end{align}\n", "\n", "Plug the Euler equation into the budget constraint:\n", "\n", "\\begin{align}\n", "c_{t}+\\frac{\\beta\\left(1+r\\right)c_{t}}{1+r} & =y_{t}+\\frac{y_{t+1}}{1+r}\\\\\n", "c_{t}+\\beta c_{t} & =y_{t}+\\frac{y_{t+1}}{1+r}\\\\\n", "\\left(1+\\beta\\right)c_{t} & =y_{t}+\\frac{y_{t+1}}{1+r}\\\\\n", "c_{t} & =\\frac{1}{1+\\beta}\\left[y_{t}+\\frac{y_{t+1}}{1+r}\\right]\n", "\\end{align}\n", "\n", "We can use the Euler equation again to find the level of consumption in the second period:\n", "\n", "\\begin{align}\n", "c_{t+1} & =\\frac{\\beta}{1+\\beta}\\left[\\left(1+r\\right)y_{t}+y_{t+1}\\right]\n", "\\end{align}\n", "\n", "Finally, we can define the stock of assets (which can be negative) that agent has at the end of period $t$. In this problem, the stock of assets will be given as the difference between first period income and consumption:\n", "\n", "\\begin{align}\n", "a\\equiv y_{t}-c_{t}=y_{t}-\\frac{1}{1+\\beta}\\left[y_{t}+\\frac{y_{t+1}}{1+r}\\right]=\\frac{\\beta}{1+\\beta}y_{t}-\\frac{1}{1+\\beta}\\frac{y_{t+1}}{1+r}\n", "\\end{align}\n", "\n", "If $a>0$, the agent is a saver ($c_{t}y_{t}$). If $a=0$, the agent is neither a saver nor a borrower and simply consumes the initial endowments ($c_{t}=y_{t}$ and $c_{t+1}=y_{t+1}$). You can see an example for the $a=0$ case below." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "y_0 = 1\n", "y_1 = 1\n", "r = 0.05\n", "β = 1/(1+r)\n", "\n", "SolveUtilityMaximizationProblem(y_0, y_1, β, r)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Comparative statics\n", "\n", "Let us now perform a few comparative statics exercises, so that we may gain intuition on the factors affecting the choice of consumption and savings.\n", "\n", "\\begin{align}\n", "a & =\\frac{\\beta}{1+\\beta}y_{t}-\\frac{1}{1+\\beta}\\frac{y_{t+1}}{1+r}\\\\\n", "c_{t} & =\\frac{1}{1+\\beta}\\left[y_{t}+\\frac{y_{t+1}}{1+r}\\right]\\\\\n", "c_{t+1} & =\\frac{\\beta}{1+\\beta}\\left[\\left(1+r\\right)y_{t}+y_{t+1}\\right]\n", "\\end{align}\n", "\n", "#### Changes in $\\beta$\n", "\n", "The higher $\\beta$ is, the more patient is our agent. Intuitively, since the agent with higher $\\beta$ cares more about the future, she would save more in the first period (and thus consume less in the first period) in order to consume more in the second period:\n", "\n", "\\begin{align}\n", "\\frac{\\partial a}{\\partial\\beta} & =\\frac{1+\\beta-\\beta}{\\left(1+\\beta\\right)^{2}}y_{t}-\\left[-\\frac{1}{\\left(1+\\beta\\right)^{2}}\\right]\\frac{y_{t+1}}{1+r}=\\frac{1}{\\left(1+\\beta\\right)^{2}}\\left[y_{t}+\\frac{y_{t+1}}{1+r}\\right]>0\\\\\n", "\\frac{\\partial c_{t}}{\\partial\\beta} & =-\\frac{1}{\\left(1+\\beta\\right)^{2}}\\left[y_{t}+\\frac{y_{t+1}}{1+r}\\right]<0\\\\\n", "\\frac{\\partial c_{t+1}}{\\partial\\beta} & =\\frac{1+\\beta-\\beta}{\\left(1+\\beta\\right)^{2}}\\left[\\left(1+r\\right)y_{t}+y_{t+1}\\right]>0\n", "\\end{align}\n", "\n", "#### Changes in $y_{t}$\n", "\n", "An increase in the first period income increases consumption in both time periods. Since the agent will want to transfer a part of the additional first period income to the second period, savings will also increase:\n", "\n", "\\begin{align}\n", "\\frac{\\partial a}{\\partial y_{t}} & =\\frac{\\beta}{1+\\beta}>0\\\\\n", "\\frac{\\partial c_{t}}{\\partial y_{t}} & =\\frac{1}{1+\\beta}>0\\\\\n", "\\frac{\\partial c_{t+1}}{\\partial y_{t}} & =\\frac{\\beta}{1+\\beta}\\left(1+r\\right)>0\n", "\\end{align}\n", "\n", "#### Changes in $y_{t+1}$\n", "An increase in the second period income increases consumption in both time periods. Since the agent will want to transfer a part of the additional second period income to the first period, savings will decrease:\n", "\n", "\\begin{align}\n", "\\frac{\\partial a}{\\partial y_{t+1}} & =-\\frac{1}{1+\\beta}\\frac{1}{1+r}<0\\\\\n", "\\frac{\\partial c_{t}}{\\partial y_{t+1}} & =\\frac{1}{1+\\beta}\\frac{1}{1+r}>0\\\\\n", "\\frac{\\partial c_{t+1}}{\\partial y_{t+1}} & =\\frac{\\beta}{1+\\beta}>0\n", "\\end{align}\n", "\n", "#### Changes in $r$\n", "An increase in the interest rate generates two effects: substitution effect and income effect. Substitution effect is generated by the change in relative prices of consumption in the first period versus consumption in the second period. It induces the agent to consume more in the second period and consume less in the first period. Income effect is generated by the fact that the PDV of income changes due to the changes in the discounting rate. The sign of the effect depends on whether an agent is a saver or a borrower. An increase in interest rates creates a positive income effect for the saver, increasing her consumption in both periods. Conversely, an increase in interest rates creates a negative income effect for the borrower, decreasing her consumption in both periods.\n", "\n", "These effects can be summarized by the following table, where pluses and minuses describe the direction of change in a variable for which we can be certain of the direction, regardless of the assumed utility function:\n", "\n", "| Effects of an increase in $r$ | Saver |   |   |   | Borrower |   |   |   |\n", "| ------------------------------- | ------ | ------- | --------- | ------ | -------- | ------- | --------- | ------ |\n", "|   |   | $c_{t}$ | $c_{t+1}$ | $a$ |   | $c_{t}$ | $c_{t+1}$ | $a$ |\n", "| Income |   | `+` | `+` | `-` |   | `-` | `-` | `+` |\n", "| Substitution |   | `-` | `+` | `+` |   | `-` | `+` | `+` |\n", "| Net |   | `?` | `+` | `?` |   | `-` | `?` | `+` |\n", "\n", "There are however also changes in variables marked with question marks, where the direction of change in a variable depends on the relative strength of substitution and income effects. In the case of a saver, if the income effect is stronger (weaker) than the substitution effect, consumption in the first period increases (decreases) and savings decrease (increase). In the case of a borrower, if the income effect is stronger (weaker) than the substitution effect, consumption in the second period decreases (increases).\n", "\n", "In figures below, the initial endowment point is labeled as $E$, the optimal choice for old $r$ as $O$ and the optimal choice for new $r$ as $O^{\\prime}$. Point $S$ represents the pure substitution effect, that is what would be the optimal choice of a consumer given new prices, if we changed the budget constraint such that the consumer's utility would be unchanged. Therefore, vector $O\\to S$ represents the substitution effect, while vector $S\\to O^{\\prime}$ represents the income effect." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Saver's case\")\n", "\n", "y_0 = 2.5\n", "y_1 = 1\n", "β = 0.95\n", "r = 0.05\n", "r_new = 1\n", "\n", "ShowIncomeAndSubstitutionEffects(y_0, y_1, β, r, r_new)\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Borrower's case\")\n", "\n", "y_0 = 0.5\n", "y_1 = 3.1\n", "β = 0.95\n", "r = 0.05\n", "r_new = 1\n", "\n", "ShowIncomeAndSubstitutionEffects(y_0, y_1, β, r, r_new)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The relative strength of the two effects depends on the shape of the indifference curves. In the case of the logarithmic utility function the reactions to the changes in the interest rate are the same, regardless of whether the agent is a borrower or a saver:\n", "\n", "\\begin{align}\n", "\\frac{\\partial a}{\\partial r} & =-\\frac{1}{1+\\beta}\\left[-\\frac{y_{t+1}}{\\left(1+r\\right)^{2}}\\right]=\\frac{1}{1+\\beta}\\frac{y_{t+1}}{\\left(1+r\\right)^{2}}>0\\\\\n", "\\frac{\\partial c_{t}}{\\partial r} & =\\frac{1}{1+\\beta}\\left[-\\frac{y_{t+1}}{\\left(1+r\\right)^{2}}\\right]=-\\frac{1}{1+\\beta}\\frac{y_{t+1}}{\\left(1+r\\right)^{2}}<0\\\\\n", "\\frac{\\partial c_{t+1}}{\\partial r} & =\\frac{\\beta}{1+\\beta}y_{t}>0\n", "\\end{align}\n", "\n", "In response to the increase in the interest rate, second period consumption increases (as long as $y_{t}>0$) and savings increase, while first period consumption decreases (as long as $y_{t+1}>0$). The negative relationship between the level of interest rates and consumption is a usual assumption in macroeconomics, and is present in the undergraduate macroeconomic models such as IS-LM and AS-AD.\n", "\n", "The case of logarithmic utility and $y_{t+1}=0$ is a very special case where both first period consumption and savings stay constant while second period consumption increases in response to an increase in the interest rate. The income and substitution effects have exactly equal strength and cancel each other out. We will use this set of assumptions when we will encounter the basic OLG model." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Figures below illustrate the dependence of the relative strength of the substitution and income effects on the specific utility function. \n", "\n", "The consumer's utility function is assumed to be the Constant Relative Risk Aversion (CRRA) function, which is commonly used in economic growth and financial literature. Parameter $\\sigma>0$ regulates the risk aversion of the consumer (the higher $\\sigma$ is, the more risk averse is the consumer):\n", "\n", "\\begin{align}\n", "U=\\frac{c_{t}^{1-\\sigma}-1}{1-\\sigma}+\\beta\\frac{c_{t+1}^{1-\\sigma}-1}{1-\\sigma}\n", "\\end{align}\n", "\n", "For $\\sigma=1$, the CRRA utility function reduces to the logarithmic function." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "print('Assuming second period income = 0')\n", "\n", "y_0 = 1\n", "y_1 = 0\n", "β = 0.95\n", "\n", "σ_vec = [0.5, 1, 2]\n", "r_vec = np.linspace(0, 0.5, 6)\n", "\n", "for σ in σ_vec:\n", " fig, ax = plt.subplots()\n", " for r in r_vec:\n", " SolveUtilityMaximizationProblemCRRA(y_0, y_1, β, σ, r, (fig, ax))\n", " plt.title('Optimal choice for different $r$ with σ = {:.1f}'.format(σ))\n", " plt.xlabel('Consumption in period $t$')\n", " plt.ylabel('Consumption in period $t+1$')\n", " plt.show()\n", " print('')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('Assuming second period income smaller then first period income')\n", "\n", "y_0 = 2\n", "y_1 = 1\n", "β = 0.95\n", "\n", "σ_vec = [1, 2, 2.5, 3]\n", "r_vec = np.linspace(0, 0.5, 6)\n", "\n", "for σ in σ_vec:\n", " fig, ax = plt.subplots()\n", " for r in r_vec:\n", " SolveUtilityMaximizationProblemCRRA(y_0, y_1, β, σ, r, (fig, ax))\n", " plt.title('Optimal choice for different $r$ with σ = {:.1f}'.format(σ))\n", " plt.xlabel('Consumption in period $t$')\n", " plt.ylabel('Consumption in period $t+1$')\n", " plt.show()\n", " print('')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('Assuming second period income bigger then first period income')\n", "\n", "y_0 = 1\n", "y_1 = 2\n", "β = 0.95\n", "\n", "σ_vec = [1, 3, 3.5, 4]\n", "r_vec = np.linspace(0, 0.5, 6)\n", "\n", "for σ in σ_vec:\n", " fig, ax = plt.subplots()\n", " for r in r_vec:\n", " SolveUtilityMaximizationProblemCRRA(y_0, y_1, β, σ, r, (fig, ax))\n", " plt.title('Optimal choice for different $r$ with σ = {:.1f}'.format(σ))\n", " plt.xlabel('Consumption in period $t$')\n", " plt.ylabel('Consumption in period $t+1$')\n", " plt.show()\n", " print('')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }