```python
# Importing packages
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import numpy as np
import sympy as sm

```

# The Edgeworth Box

In this project we will analyse a small closed economy with the Edgeworth Box. The Edgeworth box can be used to analyse several economic problems. But in this analysis we will use it to describe how two agents: a farmer and a manufacturer of windmills will act in an economy where they have to share the stock capital and labor. The project will solve the problem from the point of view of the pork producer, so the solution would be how the pork producer should optimze the production as the industry is more labor abundant than the windmill producer, which is more capital abundant.

### Presenting the model:
Pork and windmill production are defined with a **Cobb-douglas production function**, with two inputs (capital and labor).

In the economy is the pork production has capital share ($\alpha$) of 30% and labor share ($\beta$) of 70 %. The relative price of the two goods is 0.5, which means that the price of producing pork is half the of producing windmills.

Pork production function: $K^{\alpha}*L^{1-\alpha}$

Windmill production functiong: $K^{\beta}*L^{1-\beta}$

The budget constraint and isoquant of the economy is presented as following:

Budget constraint: $(I/{p_2})-({p_1}/{p_2})*c_1$

Isoquant : $Q/(L^{1-\mu})^{1/\mu}$


```python
# Defining the model
ALPHA = 0.3   # Capital share in pork production
BETA = 0.7   # Labor share in pork production

KBAR = 100 
LBAR = 100 

p = 0.5      # =Pp/Pw  relative price of pork. Windmills will have the highest price.

# It is defined from the point of view of the pork producer.
# It is assumed that both goods are produced by a Cobb-Douglas production function:

# pork production function
def P(K,L,alpha=ALPHA):
    return (K**alpha)*(L**(1-alpha))

# Windmill production function
def W(K,L,beta=BETA):
    return (K**beta)*(L**(1-beta))

# budget constraint of the economy
def budgetc(c1, p1, p2, I):
    return (I/p2)-(p1/p2)*c1

# isoquant of the economy
def isoq(L, Q, mu):
    return (Q/(L**(1-mu)))**(1/mu)
```

# Efficiency locus
Now that we have defined the production functions and the budget constraints of the economy, it is time to define the efficiency locus, which is a line that represents all allocations where the two agents' isoquants are tangent and the economy is efficient.


```python
# defining the edgeworth locus
def edgeworth(L, Kbar=KBAR, Lbar=LBAR,alpha=ALPHA, beta=BETA):
    a = (1-alpha)/alpha
    b = (1-beta)/beta
    return b*L*Kbar/(a*(Lbar-L)+b*L)
```

# Using sympy
To solve the model symbolically we have to define the symbols first:


```python
L = sm.symbols('L')
K = sm.symbols('K')
alpha = sm.symbols('alpha')
beta = sm.symbols('beta')
MU_pl = sm.symbols('MU_pl')
MU_pk = sm.symbols('MU_pk')
MU_wl = sm.symbols('MU_wl')
MU_wk = sm.symbols('MU_wk')
MRS_p = sm.symbols('MRS_p')
MRS_w = sm.symbols('MRS_w')
pr = sm.symbols('pr')

sm.init_printing(use_unicode=True)
```

First, we find the MP of labor and capital for each good, by using sympys diff function:


```python
#pork
MUpl = sm.diff((K**alpha)*L**(1-alpha),L)
MUpk = sm.diff((K**alpha)*L**(1-alpha),K)
sm.Eq(MUpl/MUpk,MRS_p)
```


```python
#Windmills
MUwl = sm.diff((K**beta)*L**(1-beta),L)
MUwk = sm.diff((K**beta)*L**(1-beta),K)
sm.Eq(MUwl/MUwk,MRS_w)
```

Now, we should be able to the equations, by setting the MRS's equal to the price relationship. But unfortunately, we are having some issues with solving systems of equations.


```python
sm.solve(sm.Eq(MUwl/MUwk/MUpl/MUpk,pr),pr=0.5)
```

# Production Possibility frontier (PPF)
The PPF's are functions which describe the maximum possible production with given levels of capital and labor. It's the PPF's that the efficiency locus are running through. Below are plotted a PPF for pork production, which will use a huge amount of labor relative to capital.


```python
def ppf(LP,Kbar=KBAR, Lbar=LBAR,alpha=ALPHA,beta=BETA):
   
    KP = edgeworth(LP, Kbar, Lbar,alpha, beta)
    RTS = (alpha/(1-alpha))*(KP/LP)
    QP = P(KP,LP,alpha)
    QW = W(Kbar-KP,Lbar-LP,beta)
    ax.scatter(QP,QW)
    Lp = np.arange(0,Lbar)
    Kp = edgeworth(Lp, Kbar, Lbar,alpha, beta)
    Qp = P(Kp,Lp,alpha)
    Qw = W(Kbar-Kp,Lbar-Lp,beta)
    ax.set_xlim(0, Lbar)
    ax.set_ylim(0, Kbar)
    ax.plot(Qp, Qw,'k--')
    ax.set_xlabel(r'$Q_{Alpha}$',fontsize=12)
    ax.set_ylabel(r'$Q_{Beta}$',fontsize=12)
    plt.show()
```


```python
# Plotting the production possibility frontier
fig, ax = plt.subplots(figsize=(7,6))
ppf(30,alpha =0.3, beta=0.7)
```

# Modelling the Edgeworth Box
The Edgeworth Box is illustrated, using the economy we defined above.


```python
def edgeplot(LP, Kbar=KBAR, Lbar=LBAR, alpha=ALPHA, beta=BETA):
    LP = 60
    KP = edgeworth(LP, Kbar, Lbar,alpha, beta)
    RTS = (alpha/(1-alpha))*(KP/LP)
    QP = P(KP,LP,alpha)
    QW = W(Kbar-KP,Lbar-LP,beta)
    print("(LP,KP)=({:4.1f}, {:4.1f})  (QP, QW)=({:4.1f}, {:4.1f})  RTS={:4.1f}"
          .format(LP,KP,QP,QW,RTS))
    Lp = np.arange(1,Lbar)
    fig, ax = plt.subplots(figsize=(12,8))
    ax.set_xlim(0, Lbar)
    ax.set_ylim(0, Kbar)
    ax.plot(Lp, edgeworth(Lp,Kbar,Lbar,alpha,beta),'k-')
    ax.plot(Lp, isoq(Lp, QP, alpha),'b-')
    ax.plot(Lp, Kbar-isoq(Lbar-Lp, QW, beta),'r-')
    ax.plot(LP, KP,'ob')
    ax.vlines(LP,0,KP, linestyles="dashed")
    ax.hlines(KP,0,LP, linestyles="dashed")
    ax.text(-6,-6,r'$O_P$',fontsize=12)
    ax.text(Lbar,Kbar,r'$O_W$',fontsize=12)
    ax.set_xlabel(r'$Labor$', fontsize=12)
    ax.set_ylabel('$Capital$', fontsize=12)
    plt.show()
```


```python
edgeplot(50)
```

# Analysis
The model shows, as expected, that the less capital intense industry will use a smaller share of the capital and more of the labor. 


```python
# Interactive edgeworth box
LP = 50
interact(edgeplot, LP=(10, LBAR-10,1),
         Kbar=fixed(KBAR), Lbar=fixed(LBAR),
         alpha= (0.1,0.9,0.1), beta=(0.1,0.9,0.1));
```


    interactive(children=(IntSlider(value=50, description='LP', max=90, min=10), FloatSlider(value=0.3, descriptio…


# Interactive model
In this interactive version of the Edgeworth Box, the reader can adjust the labor intensity and the $\alpha$ and $\beta$ values of pork production and see how windmill manufacturing reacts in the competitive economy.

# Conclusion
This Edgeworth Box is an excelent model to show how firms react to changes in other firms behavior. It showed that the firms use their comparative advantage so that a capital intensive industry will use the greatest share of capital and vice versa.


```python

```

0205b374b0c5c1d74a1e2930060e8bf0b64ad9d5
ipynb
Jupyter Notebook
modelproject/modelProject.ipynb
NumEconCopenhagen/projects-2019-ivan
35bca54e0eaf31f0dd20bf44e24103f774b1199d
MIT
modelproject/modelProject.ipynb
NumEconCopenhagen/projects-2019-ivan
35bca54e0eaf31f0dd20bf44e24103f774b1199d
MIT
2019-04-10T11:17:35.000Z
2019-05-19T20:32:07.000Z
modelproject/modelProject.ipynb
NumEconCopenhagen/projects-2019-ivan
35bca54e0eaf31f0dd20bf44e24103f774b1199d
MIT
Qwen/Qwen-72B
1. YES
2. YES