@@ -3,6 +3,8 @@ jupytext:
3
3
text_representation :
4
4
extension : .md
5
5
format_name : myst
6
+ format_version : 0.13
7
+ jupytext_version : 1.11.5
6
8
kernelspec :
7
9
display_name : Python 3 (ipykernel)
8
10
language : python
@@ -46,7 +48,6 @@ import numpy as np
46
48
import matplotlib.pyplot as plt
47
49
```
48
50
49
-
50
51
## Supply and demand
51
52
52
53
We study a market for a single good in which buyers and sellers exchange a quantity $q$ for a price $p$.
@@ -73,11 +74,11 @@ implementing the inverse demand and supply curves.
73
74
``` {code-cell} ipython3
74
75
class Market:
75
76
76
- def __init__(self,
77
- d_0=1.0, # demand intercept
78
- d_1=0.6, # demand slope
79
- s_0=0.1, # supply intercept
80
- s_1=0.4): # supply slope
77
+ def __init__(self,
78
+ d_0=1.0, # demand intercept
79
+ d_1=0.6, # demand slope
80
+ s_0=0.1, # supply intercept
81
+ s_1=0.4): # supply slope
81
82
82
83
self.d_0, self.d_1 = d_0, d_1
83
84
self.s_0, self.s_1 = s_0, s_1
@@ -87,22 +88,19 @@ class Market:
87
88
88
89
def inverse_supply(self, q):
89
90
return self.s_0 + self.s_1 * q
90
-
91
91
```
92
92
93
-
94
-
95
93
Let's create an instance.
96
94
97
95
``` {code-cell} ipython3
98
96
market = Market()
99
97
```
100
98
101
-
102
99
Here is a plot of these two functions using ` market ` .
103
100
104
101
``` {code-cell} ipython3
105
102
:tags: [hide-input]
103
+
106
104
market = Market()
107
105
108
106
grid_min, grid_max, grid_size = 0, 1.5, 200
@@ -149,11 +147,11 @@ ps = np.ones_like(q_grid) * p
149
147
150
148
fig, ax = plt.subplots()
151
149
ax.plot(q_grid, demand_curve, label='demand')
152
- ax.fill_between(q_grid[q_grid <= q],
153
- demand_curve[q_grid<= q],
154
- ps[q_grid <= q],
155
- label='consumer surplus',
156
- color='#EED1CF')
150
+ ax.fill_between(q_grid[q_grid <= q],
151
+ demand_curve[q_grid <= q],
152
+ ps[q_grid <= q],
153
+ label='consumer surplus',
154
+ color='#EED1CF')
157
155
ax.vlines(q, 0, p, linestyle="dashed", color='black', alpha=0.7)
158
156
ax.hlines(p, 0, q, linestyle="dashed", color='black', alpha=0.7)
159
157
@@ -168,7 +166,6 @@ ax.set_ylabel('price')
168
166
plt.show()
169
167
```
170
168
171
-
172
169
Consumer surplus provides a measure of total consumer welfare at quantity $q$.
173
170
174
171
The idea is that the inverse demand curve $d_0 - d_1 q$ shows a consumer's willingness to
@@ -213,11 +210,11 @@ ps = np.ones_like(q_grid) * p
213
210
214
211
fig, ax = plt.subplots()
215
212
ax.plot(q_grid, supply_curve, label='supply')
216
- ax.fill_between(q_grid[q_grid <= q],
217
- supply_curve[q_grid<= q],
218
- ps[q_grid <= q],
219
- label='producer surplus',
220
- color='#E6E6F5')
213
+ ax.fill_between(q_grid[q_grid <= q],
214
+ supply_curve[q_grid <= q],
215
+ ps[q_grid <= q],
216
+ label='producer surplus',
217
+ color='#E6E6F5')
221
218
ax.vlines(q, 0, p, linestyle="dashed", color='black', alpha=0.7)
222
219
ax.hlines(p, 0, q, linestyle="dashed", color='black', alpha=0.7)
223
220
@@ -275,14 +272,15 @@ def W(q, market):
275
272
# Unpack
276
273
d_0, d_1, s_0, s_1 = market.d_0, market.d_1, market.s_0, market.s_1
277
274
# Compute and return welfare
278
- return (d_0 - s_0) * q - 0.5 * (d_1 + s_1) * q**2
275
+ return (d_0 - s_0) * q - 0.5 * (d_1 + s_1) * q**2
279
276
```
280
277
281
278
The next figure plots welfare as a function of $q$.
282
279
283
280
284
281
```{code-cell} ipython3
285
282
:tags: [hide-input]
283
+
286
284
q_vals = np.linspace(0, 1.78, 200)
287
285
fig, ax = plt.subplots()
288
286
ax.plot(q_vals, W(q_vals, market), label='welfare')
@@ -394,11 +392,11 @@ Using the class, plot the inverse demand and supply curves $i_d$ and $i_s$
394
392
```{code-cell} ipython3
395
393
class Market:
396
394
397
- def __init__(self,
398
- d_0=1.0, # demand intercept
399
- d_1=0.6, # demand slope
400
- s_0=0.1, # supply intercept
401
- s_1=0.4): # supply slope
395
+ def __init__(self,
396
+ d_0=1.0, # demand intercept
397
+ d_1=0.6, # demand slope
398
+ s_0=0.1, # supply intercept
399
+ s_1=0.4): # supply slope
402
400
403
401
self.d_0, self.d_1 = d_0, d_1
404
402
self.s_0, self.s_1 = s_0, s_1
@@ -408,7 +406,6 @@ class Market:
408
406
409
407
def inverse_supply(self, q):
410
408
return self.s_0 + self.s_1 * q**1.8
411
-
412
409
```
413
410
414
411
Let's create an instance.
@@ -498,7 +495,8 @@ Here's a Python function that computes this value:
498
495
```{code-cell} ipython3
499
496
def W(q, market):
500
497
# Unpack
501
- d_0, d_1, s_0, s_1 = market.d_0, market.d_1, market.s_0, market.s_1
498
+ d_0, d_1 = market.d_0, market.d_1
499
+ s_0, s_1 = market.s_0, market.s_1
502
500
# Compute and return welfare
503
501
S_c = d_0 * q - d_1 * q**1.6 / 1.6
504
502
S_p = s_0 * q + s_1 * q**2.8 / 2.8
0 commit comments