{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Monetary Economics: Chapter 3, Model SIMEX" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# This line configures matplotlib to show figures embedded in the notebook, \n", "# instead of opening a new window for each figure. More about that later. \n", "# If you are using an old version of IPython, try using '%pylab inline' instead.\n", "%matplotlib inline\n", "\n", "import matplotlib.pyplot as plt\n", "\n", "from pysolve.model import Model\n", "from pysolve.utils import is_close, round_solution\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def create_simex_model():\n", " model = Model()\n", "\n", " model.set_var_default(0)\n", " model.var('Cd', desc='Consumption goods demand by households')\n", " model.var('Cs', desc='Consumption goods supply')\n", " model.var('Gs', desc='Government goods, supply')\n", " model.var('Hd', desc='Cash money demanded by households')\n", " model.var('Hh', desc='Cash money held by households')\n", " model.var('Hs', desc='Cash money supplied by the government')\n", " model.var('Nd', desc='Demand for labor')\n", " model.var('Ns', desc='Supply of labor')\n", " model.var('Td', desc='Taxes, demand')\n", " model.var('Ts', desc='Taxes, supply')\n", " model.var('Y', desc='Income = GDP')\n", " model.var('YD', desc='Disposable income of households')\n", " model.var('YDe', desc='Expected disposable income')\n", "\n", " model.set_param_default(0)\n", " model.param('Gd', desc='Government goods, demand')\n", " model.param('W', desc='Wage rate')\n", " model.param('alpha1', desc='Propensity to consume out of income')\n", " model.param('alpha2', desc='Propensity to consume o of wealth')\n", " model.param('theta', desc='Tax rate')\n", "\n", " model.add('Cs = Cd') # 3.1\n", " model.add('Gs = Gd') # 3.2\n", " model.add('Ts = Td') # 3.3\n", " model.add('Ns = Nd') # 3.4\n", " model.add('YD = (W*Ns) - Ts') # 3.5\n", " model.add('Td = theta * W * Ns') # 3.6, theta < 1.0\n", " model.add('Cd = alpha1*YDe + alpha2*Hh(-1)') # 3.7E, 0 < alpha2 < alpha1 < 1\n", " model.add('Hs - Hs(-1) = Gd - Td') # 3.8\n", " model.add('Hh - Hh(-1) = YD - Cd') # 3.9\n", " model.add('Hd - Hs(-1) = YDe - Cd') # 3.18\n", " model.add('Y = Cs + Gs') # 3.10\n", " model.add('Nd = Y/W') # 3.11\n", " model.add('YDe = YD(-1)') # 3.20\n", " \n", " return model\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Steady state solution" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "steady_state = create_simex_model()\n", "steady_state.set_values({'alpha1': 0.6,\n", " 'alpha2': 0.4,\n", " 'theta': 0.2,\n", " 'Gd': 20,\n", " 'W': 1})\n", "\n", "# Set the value so that YD(-1) gets calculated correctly\n", "steady_state.variables['YD'].value = steady_state.evaluate('Gd*(1-theta)')\n", "steady_state.variables['YD'].default = steady_state.evaluate('Gd*(1-theta)')\n", "\n", "for _ in range(100):\n", " steady_state.solve(iterations=100, threshold=1e-5)\n", "\n", " if is_close(steady_state.solutions[-2], steady_state.solutions[-1], atol=1e-4):\n", " break" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Period | 1 | 2 | 3 | ∞ |
---|---|---|---|---|
G | 20.0 | 20.0 | 20.0 | 20.0 |
Y | 0.0 | 29.6 | 39.8 | 100.0 |
T | 0.0 | 5.9 | 8.0 | 20.0 |
YD | 16.0 | 23.7 | 31.9 | 80.0 |
YDe | 0.0 | 16.0 | 23.7 | 80.0 |
C | 0.0 | 9.6 | 19.8 | 80.0 |
ΔHs | 0.0 | 14.1 | 12.0 | 0.0 |
ΔHh | 0.0 | 14.1 | 12.0 | 0.0 |
H | 0.0 | 14.1 | 26.1 | 80.0 |
ΔHd | 0.0 | 6.4 | 11.5 | 0.0 |
Hd | 0.0 | 6.4 | 17.9 | 80.0 |