Tuesday 26 April 2011

Constructing an Edgeworth Box from scratch

In order to illustrate the textbook 2-agent 'general equilibrium in consumption' model, let's begin by defining the agents' utility function, say:



We'll be using some Region and Contour plots with the following options:

For an Edgeworth Box of unit length, the code below sets up the utility contour maps (one for each player), together with the contract curve (in this case, a diagonal Line), and combines them using Show.



Note that the ContourStyle option is specified so that the subsequent (higher utility) contours are more Opaque, and hence better visible.



Next, use two RegionPlots to depict the agents' respective budget sets with a delicate Mesh, for a given initial endowment point e and relative price ρ of the 'vertical' good y.



Note that the earlier specified options for Mesh and BoundaryStyle now come into play.



We may now define the optimal solution uMax to the agents' respective utility maximization problems within the above budget sets...



...which is then used to construct the corresponding graphics, depicting the two optimal points above, as well as the tangent (maximum utility) indifference curves:


All the graphics so far can once again be combined using Show, with a few extra options added:

In particular, the FrameTicks option is used to invert the ticks corresponding to the quantities of x and y consumed by the 'blue' agent, where the InvTicks variable is set as follows:

In addition, we set the Δ variable equal to excess supply of good x at the optimum (uMax) and specify the FrameLabels accordingly using the conditional operator Which.

Finally, the entire code so far can be embedded (in place of %) in a Manipulate as follows:



where the relative price ρ is controlled using a VerticalSlider, while a Locator is used to reset the initial endowment point e by clicking anywhere inside the Box. The final product can be viewed below, and may be used, for instance, to explain the First and Second Fundamental Theorem of Welfare Economics.



Click here to download source code