Skip to content

Commit 5e2d75b

Browse files
committed
@mmcky re-read
1 parent 046db95 commit 5e2d75b

File tree

1 file changed

+14
-34
lines changed

1 file changed

+14
-34
lines changed

lectures/intro_supply_demand.md

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ from collections import namedtuple
6464

6565
Before we look at the model of supply and demand, it will be helpful to have some background on (a) consumer and producer surpluses and (b) integration.
6666

67-
(If you are comfortable with both topics you can jump to the next section.)
67+
(If you are comfortable with both topics you can jump to the {ref}`next section <integration>`.)
6868

6969
### A discrete example
7070

@@ -277,6 +277,7 @@ ax.legend()
277277
plt.show()
278278
```
279279

280+
(integration)=
280281
## Integration
281282

282283
How can we calculate the consumer and producer surplus in the continuous case?
@@ -357,7 +358,7 @@ $$
357358

358359
We call them inverse demand and supply curves because price is on the left side of the equation rather than on the right side as it would be in a direct demand or supply function.
359360

360-
We can use a [namedtuple](https://docs.python.org/3/library/collections.html#collections.namedtuple) to store the parameters for our single good market.
361+
We can use a [namedtuple](https://docs.python.org/3/library/collections.html#collections.namedtuple) to store the parameters for our single good market.
361362

362363
```{code-cell} ipython3
363364
Market = namedtuple('Market', ['d_0', # demand intercept
@@ -552,10 +553,8 @@ quantity $q$ and a fixed set of parameters.
552553
553554
```{code-cell} ipython3
554555
def W(q, market):
555-
# Unpack
556-
d_0, d_1, s_0, s_1 = market.d_0, market.d_1, market.s_0, market.s_1
557556
# Compute and return welfare
558-
return (d_0 - s_0) * q - 0.5 * (d_1 + s_1) * q**2
557+
return (market.d_0 - market.s_0) * q - 0.5 * (market.d_1 + market.s_1) * q**2
559558
```
560559
561560
The next figure plots welfare as a function of $q$.
@@ -655,35 +654,20 @@ All parameters are positive, as before.
655654
```{exercise}
656655
:label: isd_ex1
657656
658-
Define a new `Market` class that holds the same parameter values as before by
659-
changing the `inverse_demand` and `inverse_supply` methods to
660-
match these new definitions.
657+
Use the same `Market` namedtuple that holds the parameter values as before but
658+
make new `inverse_demand` and `inverse_supply` functions to match these new definitions.
661659
662-
Using the class, plot the inverse demand and supply curves $i_d$ and $i_s$
660+
Then plot the inverse demand and supply curves $i_d$ and $i_s$.
663661
664662
```
665663
666-
667664
```{solution-start} isd_ex1
668665
:class: dropdown
669666
```
670667
671-
Let us make use of a [namedtuple](https://docs.python.org/3/library/collections.html#collections.namedtuple) container provided by Python to hold the parameters of the Market.
672-
673-
```{code-cell} ipython3
674-
Market = namedtuple('Market', ['d_0', # demand intercept
675-
'd_1', # demand slope
676-
's_0', # supply intercept
677-
's_1'] # supply slope
678-
)
679-
```
680-
681-
We can now define some functions that `create` and `operate` on these Market parameters.
668+
Let's update the `inverse_demand` and `inverse_supply` functions, as defined above.
682669
683670
```{code-cell} ipython3
684-
def create_market(d_0=1.0, d_1=0.6, s_0=0.1, s_1=0.4):
685-
return Market(d_0=d_0, d_1=d_1, s_0=s_0, s_1=s_1)
686-
687671
def inverse_demand(q, model):
688672
return model.d_0 - model.d_1 * q**0.6
689673
@@ -750,7 +734,6 @@ Solve the integrals and write a function to compute this quantity numerically
750734
at given $q$.
751735
752736
Plot welfare as a function of $q$.
753-
754737
```
755738
756739
@@ -770,12 +753,9 @@ Here's a Python function that computes this value:
770753
771754
```{code-cell} ipython3
772755
def W(q, market):
773-
# Unpack
774-
d_0, d_1 = market.d_0, market.d_1
775-
s_0, s_1 = market.s_0, market.s_1
776756
# Compute and return welfare
777-
S_c = d_0 * q - d_1 * q**1.6 / 1.6
778-
S_p = s_0 * q + s_1 * q**2.8 / 2.8
757+
S_c = market.d_0 * q - market.d_1 * q**1.6 / 1.6
758+
S_p = market.s_0 * q + market.s_1 * q**2.8 / 2.8
779759
return S_c - S_p
780760
```
781761
@@ -793,7 +773,7 @@ plt.show()
793773
```
794774
795775
796-
```{exercise}
776+
````{exercise}
797777
:label: isd_ex3
798778
799779
Due to non-linearities, the new welfare function is not easy to maximize with
@@ -807,7 +787,7 @@ a section on [Optimization](https://python-programming.quantecon.org/scipy.html#
807787
is a useful resource to find out more.
808788
```
809789
810-
```
790+
````
811791
812792
813793
```{solution-start} isd_ex3
@@ -833,7 +813,7 @@ print(f"{maximizing_q: .5f}")
833813
```
834814
835815
836-
```{exercise}
816+
````{exercise}
837817
:label: isd_ex4
838818
839819
Now compute the equilibrium quantity by finding the price that equates supply
@@ -860,7 +840,7 @@ Initialize `newton` with a starting guess somewhere close to 1.0.
860840
You should find that the equilibrium price agrees with the welfare maximizing
861841
price, in line with the first fundamental welfare theorem.
862842
863-
```
843+
````
864844
865845
866846
```{solution-start} isd_ex4

0 commit comments

Comments
 (0)