Ask Your Question
1

Deriving a contract curve in sage

asked 2020-07-15 23:07:14 +0100

EconJohn gravatar image

updated 2020-07-16 18:37:56 +0100

Im trying to solve for the set of pareto efficent allocations using sage. So far i'm on the right track with my code of a two by two economy with consumer A and consumer B with resource constraints given by R1 and R2 for the total amount of good 1 and good 2.

xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b;
Ub = xb1^a*xb2^b;
R1=xa1+xb1;
R2=xa2+xb2;
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
solve([MRSA==MRSB],xa1)

The solution this code gives us is:

[xa1 == xa2*xb1/xb2]

I want to reduce xa1 to be a function of R1,R2 and xb1.

on paper this could be found by using the definitions of R1 and R2.

I've tried this before by including these variables in the square brackets of the solution but with no luck. Any help is appreciated.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2020-07-16 19:00:01 +0100

EconJohn gravatar image

Managed to figure out this problem. I found that if you define your constraints in the context of the solve() function we get a clearer picture. The contract curve from consumer A's perspective is given by the following:

xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b;
Ub = xb1^a*xb2^b;
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
solve([MRSA==MRSB,R1==xa1+xb1,R2==xa2+xb2],xa1,xb1,xb2)

Out: [[xa1 == R1*xa2/R2, xb1 == (R1*R2 - R1*xa2)/R2, xb2 == R2 - xa2]]

If we were to conciser consumer B's perspective we have to only change the last line of code to:

solve([MRSA==MRSB,R1==xa1+xb1,R2==xa2+xb2],xa1,xb1,xa2)

Out:  [[xa1 == (R1*R2 - R1*xb2)/R2, xb1 == R1*xb2/R2, xa2 == R2 - xb2]]

The reason why we need to change this last line of code is due to the nature of the solver.

Pretty happy with this result.

edit flag offensive delete link more
1

answered 2020-07-16 13:54:26 +0100

Emmanuel Charpentier gravatar image

updated 2020-07-16 19:09:11 +0100

You can't : your solution involves xa2, which doesn't appear in the definition of R1 and R2 ; xa2 is an independent quantity.

May I suggest proofing your problem ?

EDIT : After typo correction, it's clearer. And CAN be solved. Let's rewrite the problem a bit:

xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b
Ub = xb1^a*xb2^b
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
Sol=solve([MRSA==MRSB],xa1)

Let's define R1 and R2 by equations, not assignments :

E1=R1==xa1+xb1
E2=R2==xa2+xb2

Your solution is :

sage: Sol
[xa1 == xa2*xb1/xb2]

We can solve E1 and E2 for xa1 and xa2 (thus getting tid of th,R2andxb2` :em) :

sage: solve([E1,E2],[xa1,xa2])[0]
[xa1 == R1 - xb1, xa2 == R2 - xb2]

Let(' substitute that into your solution :

sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0])
R1 - xb1 == (R2 - xb2)*xb1/xb2

which gives us xb1 as a function of R1, R2 and xb1 :

sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0]).solve(xb1)
[xb1 == R1*xb2/R2]

which if I understand you correctly,is the result you sought.

HTH,

edit flag offensive delete link more

Comments

The form on paper you can solve this by subbing in our resource constraints and getting xa1==(R1-xa1)*xb1/(R2-xb1) further simplifying should give us xa1==xb1*R1/R2. I just havent figured out how to do this in sage.

EconJohn gravatar imageEconJohn ( 2020-07-16 16:27:25 +0100 )edit

This :

R1=xa1+xb1;
R2=xb1+xb2;

is curiously asymetric. Could you check ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-07-16 17:37:59 +0100 )edit

How is it asymmetric?

EconJohn gravatar imageEconJohn ( 2020-07-16 18:08:37 +0100 )edit

You seem to describe two symmetric actors. I would expect either :

R1=xa1+xb1;
R2=xa2+xb2;

or

R1=xa1+xa2;
R2=xb1+xb2;
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-07-16 18:35:26 +0100 )edit

Oh I see the issue. It was right in front of me. Editing

EconJohn gravatar imageEconJohn ( 2020-07-16 18:37:38 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-07-15 23:07:14 +0100

Seen: 341 times

Last updated: Jul 16 '20