Skip to content

Commit 637aed6

Browse files
Tom's edits of dmd-supply lecture
1 parent b07673f commit 637aed6

File tree

1 file changed

+143
-5
lines changed

1 file changed

+143
-5
lines changed

in-work/quantecon_undergrad_notes_tom_3.md renamed to in-work/supply_demand_foundations_v2.md

Lines changed: 143 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ Then we compute the equilibrium price vector using the inverse demand or supply
981981

982982

983983
```python
984+
984985
class Production_economy:
985986
def __init__(self, Pi, b, h, J, mu):
986987
"""
@@ -1015,6 +1016,24 @@ class Production_economy:
10151016

10161017
return c, p
10171018

1019+
def equilibrium_with_monopoly(self):
1020+
"""
1021+
Compute the equilibrium price and allocation when there is a monopolist supplier
1022+
"""
1023+
Pi, b, h, mu, J = self.Pi, self.b, self.h, self.mu, self.J
1024+
H = .5*(J+J.T)
1025+
1026+
# allocation
1027+
q = inv(mu*H + 2*Pi.T@Pi)@(Pi.T@b - mu*h)
1028+
1029+
# price
1030+
p = 1/mu * (Pi.T@b - Pi.T@Pi@q)
1031+
1032+
if any(Pi @ q - b >= 0):
1033+
raise Exception('invalid result: set bliss points further away')
1034+
1035+
return q, p
1036+
10181037
def compute_surplus(self):
10191038
"""
10201039
Compute consumer and producer surplus for single good case
@@ -1038,7 +1057,7 @@ class Production_economy:
10381057
return c_surplus, p_surplus
10391058

10401059

1041-
def plot_PE_single_good(PE):
1060+
def plot_competitive_equilibrium(PE):
10421061
"""
10431062
Plot demand and supply curves, producer/consumer surpluses, and equilibrium for
10441063
a single good production economy
@@ -1067,11 +1086,14 @@ def plot_PE_single_good(PE):
10671086
plt.figure(figsize=[7,5])
10681087
plt.plot(xs, supply_curve, label='Supply', color='#020060')
10691088
plt.plot(xs, demand_curve, label='Demand', color='#600001')
1070-
plt.fill_between(xs[xs<=c], supply_curve[xs<=c], ps[xs<=c], label='Producer surplus', color='#E6E6F5')
1089+
10711090
plt.fill_between(xs[xs<=c], demand_curve[xs<=c], ps[xs<=c], label='Consumer surplus', color='#EED1CF')
1091+
plt.fill_between(xs[xs<=c], supply_curve[xs<=c], ps[xs<=c], label='Producer surplus', color='#E6E6F5')
1092+
10721093
plt.vlines(c, 0, p, linestyle="dashed", color='black', alpha=0.7)
10731094
plt.hlines(p, 0, c, linestyle="dashed", color='black', alpha=0.7)
10741095
plt.scatter(c, p, zorder=10, label='Competitive equilibrium', color='#600001')
1096+
10751097
plt.legend(loc='upper right')
10761098
plt.margins(x=0, y=0)
10771099
plt.ylim(0)
@@ -1105,7 +1127,7 @@ print('Competitive equilibrium price:', p.item())
11051127
print('Competitive equilibrium allocation:', c.item())
11061128

11071129
# plot
1108-
plot_PE_single_good(PE)
1130+
plot_competitive_equilibrium(PE)
11091131
```
11101132

11111133
```python
@@ -1125,7 +1147,7 @@ print('Competitive equilibrium price:', p.item())
11251147
print('Competitive equilibrium allocation:', c.item())
11261148

11271149
# plot
1128-
plot_PE_single_good(PE)
1150+
plot_competitive_equilibrium(PE)
11291151
```
11301152

11311153
```python
@@ -1146,7 +1168,7 @@ print('Competitive equilibrium price:', p.item())
11461168
print('Competitive equilibrium allocation:', c.item())
11471169

11481170
# plot
1149-
plot_PE_single_good(PE)
1171+
plot_competitive_equilibrium(PE)
11501172
```
11511173

11521174
This raises both the equilibrium price and quantity.
@@ -1209,3 +1231,119 @@ c, p = PE.competitive_equilibrium()
12091231
print('Competitive equilibrium price:', p)
12101232
print('Competitive equilibrium allocation:', c)
12111233
```
1234+
1235+
### A Monopolist Supplier
1236+
1237+
Let us follow the above digression and consider a monopolist supplier in this economy. We add a method to the `production_economy` class we built above to compute the equilibrium price and allocation when there is a monopolist supplier. Since the supplier now has the price-setting power,
1238+
- we first compute the optimal quantity that solves the monopolist's profit maximization problem.
1239+
- Then we derive the required price level from the consumer's inverse supply curve.
1240+
1241+
Next, we use a graph for the single good case to illustrate the difference between a competitive equilibrium and an equilibrium with a monopolist supplier. Recall that in a competitive equilibrium of the economy, the price-taking supplier equalizes the marginal revenue $p$ with the marginal cost $h + Hq$. This yields the inverse supply curve. In a monopolist economy, the marginal revenue of the firm is a function of the quantity it chooses:
1242+
$$
1243+
MR(q) = -2\mu^{-1}\Pi^{\top}\Pi q+\mu^{-1}\Pi^{\top}b,
1244+
$$
1245+
which the monopolist supplier equalizes with the marginal cost.
1246+
1247+
Our plot illustrates the fact that the monopolist supplier's equilibrium output is lower than either the competitive equilibrium or the social optimal level. In a single good case, this equilibrium is associated with a higher price of the good.
1248+
1249+
```python
1250+
def plot_monopoly(PE):
1251+
"""
1252+
Plot demand curve, marginal production cost and revenue, surpluses and the
1253+
equilibrium in a monopolist supplier economy with a single good
1254+
1255+
Args:
1256+
PE (class): A initialized production economy class
1257+
"""
1258+
# get singleton value
1259+
J, h, Pi, b, mu = PE.J.item(), PE.h.item(), PE.Pi.item(), PE.b.item(), PE.mu
1260+
H = J
1261+
1262+
# compute competitive equilibrium
1263+
c, p = PE.competitive_equilibrium()
1264+
q, pm = PE.equilibrium_with_monopoly()
1265+
c, p, q, pm = c.item(), p.item(), q.item(), pm.item()
1266+
1267+
# compute
1268+
1269+
# inverse supply/demand curve
1270+
marg_cost = lambda x: h + H*x
1271+
marg_rev = lambda x: -2*1/mu*Pi*Pi*x + 1/mu*Pi*b
1272+
demand_inv = lambda x: 1/mu*(Pi*b - Pi*Pi*x)
1273+
1274+
xs = np.linspace(0, 2*c, 100)
1275+
pms = np.ones(100) * pm
1276+
marg_cost_curve = marg_cost(xs)
1277+
marg_rev_curve = marg_rev(xs)
1278+
demand_curve = demand_inv(xs)
1279+
1280+
# plot
1281+
plt.figure(figsize=[7,5])
1282+
plt.plot(xs, marg_cost_curve, label='Marginal cost', color='#020060')
1283+
plt.plot(xs, marg_rev_curve, label='Marginal revenue', color='#E55B13')
1284+
plt.plot(xs, demand_curve, label='Demand', color='#600001')
1285+
1286+
plt.fill_between(xs[xs<=q], demand_curve[xs<=q], pms[xs<=q], label='Consumer surplus', color='#EED1CF')
1287+
plt.fill_between(xs[xs<=q], marg_cost_curve[xs<=q], pms[xs<=q], label='Producer surplus', color='#E6E6F5')
1288+
1289+
plt.vlines(c, 0, p, linestyle="dashed", color='black', alpha=0.7)
1290+
plt.hlines(p, 0, c, linestyle="dashed", color='black', alpha=0.7)
1291+
plt.scatter(c, p, zorder=10, label='Competitive equilibrium', color='#600001')
1292+
1293+
plt.vlines(q, 0, pm, linestyle="dashed", color='black', alpha=0.7)
1294+
plt.hlines(pm, 0, q, linestyle="dashed", color='black', alpha=0.7)
1295+
plt.scatter(q, pm, zorder=10, label='Equilibrium with monopoly', color='#E55B13')
1296+
1297+
plt.legend(loc='upper right')
1298+
plt.margins(x=0, y=0)
1299+
plt.ylim(0)
1300+
plt.xlabel('Quantity')
1301+
plt.ylabel('Price')
1302+
plt.show()
1303+
```
1304+
1305+
#### A multiple good example
1306+
1307+
```python
1308+
Pi = np.array([[1, 0],
1309+
[0, 1.2]])
1310+
b = np.array([10, 10])
1311+
1312+
h = np.array([0.5, 0.5])
1313+
J = np.array([[1, 0.5],
1314+
[0.5, 1]])
1315+
mu = 1
1316+
1317+
PE = Production_economy(Pi, b, h, J, mu)
1318+
c, p = PE.competitive_equilibrium()
1319+
q, pm = PE.equilibrium_with_monopoly()
1320+
1321+
print('Competitive equilibrium price:', p)
1322+
print('Competitive equilibrium allocation:', c)
1323+
1324+
print('Equilibrium with monopolist supplier price:', pm)
1325+
print('Equilibrium with monopolist supplier allocation:', q)
1326+
```
1327+
1328+
#### A single-good example
1329+
1330+
```python
1331+
Pi = np.array([[1]]) # the matrix now is a singleton
1332+
b = np.array([10])
1333+
h = np.array([0.5])
1334+
J = np.array([[1]])
1335+
mu = 1
1336+
1337+
PE = Production_economy(Pi, b, h, J, mu)
1338+
c, p = PE.competitive_equilibrium()
1339+
q, pm = PE.equilibrium_with_monopoly()
1340+
1341+
print('Competitive equilibrium price:', p.item())
1342+
print('Competitive equilibrium allocation:', c.item())
1343+
1344+
print('Equilibrium with monopolist supplier price:', pm.item())
1345+
print('Equilibrium with monopolist supplier allocation:', q.item())
1346+
1347+
# plot
1348+
plot_monopoly(PE)
1349+
```

0 commit comments

Comments
 (0)