Skip to content

Commit e27eacd

Browse files
Add ipython config
1 parent 5f66cd4 commit e27eacd

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

lectures/supply_demand_heterogeneity.md

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
---
2+
jupytext:
3+
text_representation:
4+
extension: .md
5+
format_name: myst
6+
kernelspec:
7+
display_name: Python 3 (ipykernel)
8+
language: python
9+
name: python3
10+
---
111
# Market Equilibrium with Heterogeneity
212

313

@@ -110,7 +120,7 @@ The class will include a test to make sure that $b > > \Pi e $ and raise an exc
110120
Now let's proceed to code.
111121
<!-- #endregion -->
112122
113-
```python
123+
```{code-cell} ipython3
114124
# import some packages
115125
import numpy as np
116126
import pandas as pd
@@ -220,7 +230,7 @@ $$
220230
Thus, we have verified that, up to choice of a numeraire in which to express absolute prices, the price vector in our representative consumer economy is the same as that in an underlying economy with multiple consumers.
221231
<!-- #endregion -->
222232

223-
```python
233+
```{code-cell} ipython3
224234
class ExchangeEconomy:
225235
def __init__(self, Pi, bs, es, Ws=None, thres=4):
226236
"""
@@ -291,7 +301,7 @@ class ExchangeEconomy:
291301

292302

293303

294-
```python
304+
```{code-cell} ipython3
295305
Pi = np.array([[1, 0],
296306
[0, 1]])
297307
@@ -310,7 +320,7 @@ print('Competitive equilibrium allocation:', c_s)
310320

311321
What happens if the first consumer likes the first good more and the second consumer likes the second good more?
312322

313-
```python
323+
```{code-cell} ipython3
314324
bs = [np.array([6, 5]), # first consumer's bliss points
315325
np.array([5, 6])] # second consumer's bliss points
316326
@@ -327,7 +337,7 @@ print('Competitive equilibrium allocation:', c_s)
327337

328338
Let the first consumer be poorer.
329339

330-
```python
340+
```{code-cell} ipython3
331341
bs = [np.array([5, 5]), # first consumer's bliss points
332342
np.array([5, 5])] # second consumer's bliss points
333343
@@ -344,7 +354,7 @@ print('Competitive equilibrium allocation:', c_s)
344354

345355
Now let's construct an autarky (i.e, no-trade) equilibrium.
346356

347-
```python
357+
```{code-cell} ipython3
348358
bs = [np.array([4, 6]), # first consumer's bliss points
349359
np.array([6, 4])] # second consumer's bliss points
350360
@@ -361,7 +371,7 @@ print('Competitive equilibrium allocation:', c_s)
361371

362372
Now let's redistribute endowments before trade.
363373

364-
```python
374+
```{code-cell} ipython3
365375
bs = [np.array([5, 5]), # first consumer's bliss points
366376
np.array([5, 5])] # second consumer's bliss points
367377
@@ -381,7 +391,7 @@ print('Competitive equilibrium allocation:', c_s)
381391
Now let's use the tricks described above to study a dynamic economy, one with two periods.
382392

383393

384-
```python
394+
```{code-cell} ipython3
385395
beta = 0.95
386396
387397
Pi = np.array([[1, 0],
@@ -405,7 +415,7 @@ We use the tricks described above to interpret $c_1, c_2$ as "Arrow securities"
405415

406416

407417

408-
```python
418+
```{code-cell} ipython3
409419
prob = 0.7
410420
411421
Pi = np.array([[np.sqrt(prob), 0],
@@ -432,7 +442,7 @@ To compute a competitive equilibrium for a production economy where demand curve
432442
Then we compute the equilibrium price vector using the inverse demand or supply curve.
433443

434444

435-
```python
445+
```{code-cell} ipython3
436446
437447
class ProductionEconomy:
438448
def __init__(self, Pi, b, h, J, mu):
@@ -569,7 +579,7 @@ To do this we
569579

570580
* do experiments in which we shift $b$ and watch what happens to $p, c$.
571581

572-
```python
582+
```{code-cell} ipython3
573583
Pi = np.array([[1]]) # the matrix now is a singleton
574584
b = np.array([10])
575585
h = np.array([0.5])
@@ -586,7 +596,7 @@ print('Competitive equilibrium allocation:', c.item())
586596
plot_competitive_equilibrium(PE)
587597
```
588598

589-
```python
599+
```{code-cell} ipython3
590600
c_surplus, p_surplus = PE.compute_surplus()
591601
592602
print('Consumer surplus:', c_surplus.item())
@@ -595,7 +605,7 @@ print('Producer surplus:', p_surplus.item())
595605

596606
Let's give consumers a lower welfare weight by raising $\mu$.
597607

598-
```python
608+
```{code-cell} ipython3
599609
PE.mu = 2
600610
c, p = PE.competitive_equilibrium()
601611
@@ -606,7 +616,7 @@ print('Competitive equilibrium allocation:', c.item())
606616
plot_competitive_equilibrium(PE)
607617
```
608618

609-
```python
619+
```{code-cell} ipython3
610620
c_surplus, p_surplus = PE.compute_surplus()
611621
612622
print('Consumer surplus:', c_surplus.item())
@@ -615,7 +625,7 @@ print('Producer surplus:', p_surplus.item())
615625

616626
Now we change the bliss point so that the consumer derives more utility from consumption.
617627

618-
```python
628+
```{code-cell} ipython3
619629
PE.mu = 1
620630
PE.b = PE.b * 1.5
621631
c, p = PE.competitive_equilibrium()
@@ -637,7 +647,7 @@ This raises both the equilibrium price and quantity.
637647
* we can do experiments with a **diagonal** $\Pi$ and also with a **non-diagonal** $\Pi$ matrices to study how cross-slopes affect responses of $p$ and $c$ to various shifts in $b$
638648

639649

640-
```python
650+
```{code-cell} ipython3
641651
Pi = np.array([[1, 0],
642652
[0, 1]])
643653
b = np.array([10, 10])
@@ -654,7 +664,7 @@ print('Competitive equilibrium price:', p)
654664
print('Competitive equilibrium allocation:', c)
655665
```
656666

657-
```python
667+
```{code-cell} ipython3
658668
PE.b = np.array([12, 10])
659669
660670
c, p = PE.competitive_equilibrium()
@@ -663,7 +673,7 @@ print('Competitive equilibrium price:', p)
663673
print('Competitive equilibrium allocation:', c)
664674
```
665675

666-
```python
676+
```{code-cell} ipython3
667677
Pi = np.array([[1, 0.5],
668678
[0.5, 1]])
669679
b = np.array([10, 10])
@@ -680,7 +690,7 @@ print('Competitive equilibrium price:', p)
680690
print('Competitive equilibrium allocation:', c)
681691
```
682692

683-
```python
693+
```{code-cell} ipython3
684694
PE.b = np.array([12, 10])
685695
c, p = PE.competitive_equilibrium()
686696
@@ -719,7 +729,7 @@ The plot indicates that the monopolist's sets output lower than either the comp
719729

720730
In a single good case, this equilibrium is associated with a higher price of the good.
721731

722-
```python
732+
```{code-cell} ipython3
723733
def plot_monopoly(PE):
724734
"""
725735
Plot demand curve, marginal production cost and revenue, surpluses and the
@@ -779,7 +789,7 @@ def plot_monopoly(PE):
779789

780790
Let's study compare competitive equilibrium and monopoly outcomes in a multiple goods economy.
781791

782-
```python
792+
```{code-cell} ipython3
783793
Pi = np.array([[1, 0],
784794
[0, 1.2]])
785795
b = np.array([10, 10])
@@ -802,7 +812,7 @@ print('Equilibrium with monopolist supplier allocation:', q)
802812

803813
#### A Single-Good Example
804814

805-
```python
815+
```{code-cell} ipython3
806816
Pi = np.array([[1]]) # the matrix now is a singleton
807817
b = np.array([10])
808818
h = np.array([0.5])

0 commit comments

Comments
 (0)