{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Weekly exercise 14: Stochastic consumption-savings model in finite horizon\n", "\n", "In this exercise you continue building up the `deaton()` class by adding the finite horizon version of the model.\n", "\n", "Start by copying the `deaton()` class code from lecture notebook 36. Make the following modifications:\n", "\n", "- add an attribute horizon to the model which is set to ‘infinite’ by default, but can take numerical values fixing the number of periods in the model $ T $ \n", "- modify the `__repr__()` method to output whether the model is finite or infinite horizon \n", "- code up the backwards induction solver for the finite horizon version of the model in a separate method `solver_backwards_induction()` with the only argument callback function (but using horizon attribute for the maximum number of periods). See lecture notebook 27 for examples of backward induction solvers \n", "- modify the simulator method to default to the $ T $ set in the horizon attribute when it is not equal ‘infinite’ \n", "\n", "\n", "Run separate simulations of the model for a few values of parameters, and discuss their similarities and differences." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Your code here" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "m = deaton(ngrid=100,nchgrid=250,sigma=.2,R=1.05,beta=.975,nquad=10)\n", "m.horizon=12\n", "print(m)\n", "v,c = m.solve_plot(solver='vfi')\n", "sims = m.simulator(init_wealth=[1,2,3],T=5)" ] } ], "metadata": { "date": 1627475014.609771, "filename": "exercise14.rst", "kernelspec": { "display_name": "Python", "language": "python3", "name": "python3" }, "title": "Weekly exercise 14: Stochastic consumption-savings model in finite horizon" }, "nbformat": 4, "nbformat_minor": 4 }