{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Weekly exercise 4: Optimal choice in the bungle good market\n", "\n", "In this exercise I ask you to apply the machinery of bungled goods\n", "we have created in video 08 for answering some economic questions.\n", "Make sure you use the code written in that video which is stored\n", "in the notebook *08_bundles_ex2*." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "# copy the working code of the bungle_good class into this cell and run it" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Optimal choice of bundle goods\n", "\n", "Consider a consumer with a utility function over the individual goods\n", "given by\n", "\n", "$$\n", "u(x_1,\\dots,x_7)=\\log(x_1+1)+\\big((x_2)^{0.4}+0.5(x_3)^{0.4}\\big)^{2.5}-0.5\\log(x_4+1)-0.2(x_5*x_6)^{0.2}+2\\log(x_7+1).\n", "$$\n", "\n", "Find the optimal set of bundle goods to be consumed by comparing\n", "different combinations of the available bundles shown below.\n", "\n", "There are only three bundle goods on the market, so we\n", "can afford a brute force optimization algorithm implemented as a\n", "triple nested loop, with each level corresponding to one bundle good\n", "and looping from 0 to some reasonable number (think which number\n", "would be reasonable).\n", "\n", "Compute the optimal choice for budgets of 100, 200 and 300 price units.\n", "\n", "Use the starter code below. Each occurrence of **@@@** has to be replaced with appropriate code." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Available bundle goods\n", "a = bundle_good([2,0,1,3,1,1,0],10.50)\n", "b = bundle_good([0,5,0,4,2,2,2],15.36)\n", "c = bundle_good([1,0,1,2,0,5,4],12.72)\n", "market = [a,b,c]\n", "\n", "import math\n", "\n", "# utility function\n", "def u(x):\n", " '''Returns the utility of a bundle'''\n", " return @@@\n", "\n", "# optimization routine\n", "def optim(budget,util,market):\n", " '''Returns the optimal combination of goods at the market, given the budget'''\n", " nn = @@@ #heuristic for the maximum quantity to check\n", " # loop over all combination of three bundles to find max utility\n", " m = -float('inf') #initialize with negative infinity\n", " for i in range(nn):\n", " for j in range(nn):\n", " for k in range(nn):\n", " bnd = @@@ # combination of so many of each of the three bundled goods\n", " u = util(@@@)\n", " if bnd.price <= budget and m