In this exercise I ask you to apply the machinery of bungled goods we have created in video 08 for answering some economic questions. Make sure you use the code written in that video which is stored in the notebook 08_bundles_ex2.
# copy the working code of the bungle_good class into this cell and run it
Consider a consumer with a utility function over the individual goods given by
$$ 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). $$Find the optimal set of bundle goods to be consumed by comparing different combinations of the available bundles shown below.
There are only three bundle goods on the market, so we can afford a brute force optimization algorithm implemented as a triple nested loop, with each level corresponding to one bundle good and looping from 0 to some reasonable number (think which number would be reasonable).
Compute the optimal choice for budgets of 100, 200 and 300 price units.
Use the starter code below. Each occurrence of @@@ has to be replaced with appropriate code.
# Available bundle goods
a = bundle_good([2,0,1,3,1,1,0],10.50)
b = bundle_good([0,5,0,4,2,2,2],15.36)
c = bundle_good([1,0,1,2,0,5,4],12.72)
market = [a,b,c]
import math
# utility function
def u(x):
'''Returns the utility of a bundle'''
return @@@
# optimization routine
def optim(budget,util,market):
'''Returns the optimal combination of goods at the market, given the budget'''
nn = @@@ #heuristic for the maximum quantity to check
# loop over all combination of three bundles to find max utility
m = -float('inf') #initialize with negative infinity
for i in range(nn):
for j in range(nn):
for k in range(nn):
bnd = @@@ # combination of so many of each of the three bundled goods
u = util(@@@)
if bnd.price <= budget and m<u:
# found new maximum which is within the budget
m = @@@ # remember the new max utility
x = @@@ # remember the combination of bundle goods where max is attained
return x #return the optimal combination of goods
def report(budget,util,x,market):
'''Makes nice readable output'''
@@@
# main program
for budget in [@@@]:
x=optim(budget,u,market)
report(budget,u,x,market)
Imagine the newly introduced sales tax raised all prices by 15%. Recompute the optimal choices in previous question.
Do the optimal choices change, and how?
# Write your code here
Imagine the sale for bundle good c lowers its price by 20%. Recompute the optimal choices in previous question.
Do the optimal choices change, and how?
# Write your code here