Skip to content

Review supply demand #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 37 additions & 39 deletions lectures/intro_supply_demand.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.5
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand All @@ -11,7 +13,7 @@ kernelspec:

# Introduction to Supply and Demand

## Outline
## Overview

This lecture is about some models of equilibrium prices and quantities, one of
the main topics of elementary microeconomics.
Expand All @@ -31,9 +33,9 @@ Key infrastructure concepts that we'll encounter in this lecture are
* social welfare as the sum of consumer and producer surpluses
* relationship between equilibrium quantity and social welfare optimum

Throughout the lectures, we'll assume that inverse demand and supply curves are **affine** functions of output.
Throughout the lectures, we'll assume that inverse demand and supply curves are **affine** functions of quantity.

("Affine" means "linear plus a constant".)
("Affine" means "linear plus a constant" and [here](https://math.stackexchange.com/questions/275310/what-is-the-difference-between-linear-and-affine-function) is a nice discussion about it.)

We'll also assume affine inverse supply and demand functions when we study models with multiple consumption goods in our {doc}`subsequent lecture <supply_demand_multiple_goods>`.

Expand All @@ -46,7 +48,6 @@ import numpy as np
import matplotlib.pyplot as plt
```


## Supply and demand

We study a market for a single good in which buyers and sellers exchange a quantity $q$ for a price $p$.
Expand All @@ -73,11 +74,11 @@ implementing the inverse demand and supply curves.
```{code-cell} ipython3
class Market:

def __init__(self,
d_0=1.0, # demand intercept
d_1=0.6, # demand slope
s_0=0.1, # supply intercept
s_1=0.4): # supply slope
def __init__(self,
d_0=1.0, # demand intercept
d_1=0.6, # demand slope
s_0=0.1, # supply intercept
s_1=0.4): # supply slope

self.d_0, self.d_1 = d_0, d_1
self.s_0, self.s_1 = s_0, s_1
Expand All @@ -87,22 +88,19 @@ class Market:

def inverse_supply(self, q):
return self.s_0 + self.s_1 * q

```



Let's create an instance.

```{code-cell} ipython3
market = Market()
```


Here is a plot of these two functions using `market`.

```{code-cell} ipython3
:tags: [hide-input]

market = Market()

grid_min, grid_max, grid_size = 0, 1.5, 200
Expand All @@ -122,7 +120,7 @@ ax.set_ylabel('price')
plt.show()
```

In the above graph, an **equilibrium** price, quantity pair occurs at the intersection of the supply and demand curves.
In the above graph, an **equilibrium** price-quantity pair occurs at the intersection of the supply and demand curves.

### Consumer surplus

Expand All @@ -135,7 +133,7 @@ curve minus $p q$:
$$
S_c(q) :=
\int_0^{q} (d_0 - d_1 x) dx - p q
$$
$$ (eq:cstm_spls)

The next figure illustrates

Expand All @@ -149,11 +147,11 @@ ps = np.ones_like(q_grid) * p

fig, ax = plt.subplots()
ax.plot(q_grid, demand_curve, label='demand')
ax.fill_between(q_grid[q_grid <= q],
demand_curve[q_grid<=q],
ps[q_grid <= q],
label='consumer surplus',
color='#EED1CF')
ax.fill_between(q_grid[q_grid <= q],
demand_curve[q_grid <= q],
ps[q_grid <= q],
label='consumer surplus',
color='#EED1CF')
ax.vlines(q, 0, p, linestyle="dashed", color='black', alpha=0.7)
ax.hlines(p, 0, q, linestyle="dashed", color='black', alpha=0.7)

Expand All @@ -168,18 +166,17 @@ ax.set_ylabel('price')
plt.show()
```


Consumer surplus provides a measure of total consumer welfare at quantity $q$.

The idea is that the inverse demand curve $d_0 - d_1 q$ shows a consumer's willingness to
pay for an additional increment of the good at a given quantity $q$.
pay for an additional increment of the good at a given quantity $q$.

The difference between willingness to pay and the actual price is consumer surplus.

The value $S_c(q)$ is the "sum" (i.e., integral) of these surpluses when the total
quantity purchased is $q$ and the purchase price is $p$.

Evaluating the integral in the definition of consumer surplus gives
Evaluating the integral in the definition of consumer surplus {eq}`eq:cstm_spls` gives

$$
S_c(q)
Expand All @@ -200,7 +197,7 @@ We define **producer surplus** as $p q$ minus the area under an inverse supply c
$$
S_p(q)
:= p q - \int_0^q (s_0 + s_1 x) dx
$$
$$ (eq:pdcr_spls)

The next figure illustrates

Expand All @@ -213,11 +210,11 @@ ps = np.ones_like(q_grid) * p

fig, ax = plt.subplots()
ax.plot(q_grid, supply_curve, label='supply')
ax.fill_between(q_grid[q_grid <= q],
supply_curve[q_grid<=q],
ps[q_grid <= q],
label='producer surplus',
color='#E6E6F5')
ax.fill_between(q_grid[q_grid <= q],
supply_curve[q_grid <= q],
ps[q_grid <= q],
label='producer surplus',
color='#E6E6F5')
ax.vlines(q, 0, p, linestyle="dashed", color='black', alpha=0.7)
ax.hlines(p, 0, q, linestyle="dashed", color='black', alpha=0.7)

Expand All @@ -243,7 +240,7 @@ The difference between willingness to sell and the actual price is producer surp

The value $S_p(q)$ is the integral of these surpluses.

Evaluating the integral in the definition of consumer surplus gives
Evaluating the integral in the definition of producer surplus {eq}`eq:pdcr_spls` gives

$$
S_p(q) = pq - s_0 q - \frac{1}{2} s_1 q^2
Expand Down Expand Up @@ -275,14 +272,15 @@ def W(q, market):
# Unpack
d_0, d_1, s_0, s_1 = market.d_0, market.d_1, market.s_0, market.s_1
# Compute and return welfare
return (d_0 - s_0) * q - 0.5 * (d_1 + s_1) * q**2
return (d_0 - s_0) * q - 0.5 * (d_1 + s_1) * q**2
```

The next figure plots welfare as a function of $q$.


```{code-cell} ipython3
:tags: [hide-input]

q_vals = np.linspace(0, 1.78, 200)
fig, ax = plt.subplots()
ax.plot(q_vals, W(q_vals, market), label='welfare')
Expand Down Expand Up @@ -394,11 +392,11 @@ Using the class, plot the inverse demand and supply curves $i_d$ and $i_s$
```{code-cell} ipython3
class Market:

def __init__(self,
d_0=1.0, # demand intercept
d_1=0.6, # demand slope
s_0=0.1, # supply intercept
s_1=0.4): # supply slope
def __init__(self,
d_0=1.0, # demand intercept
d_1=0.6, # demand slope
s_0=0.1, # supply intercept
s_1=0.4): # supply slope

self.d_0, self.d_1 = d_0, d_1
self.s_0, self.s_1 = s_0, s_1
Expand All @@ -408,7 +406,6 @@ class Market:

def inverse_supply(self, q):
return self.s_0 + self.s_1 * q**1.8

```

Let's create an instance.
Expand Down Expand Up @@ -498,7 +495,8 @@ Here's a Python function that computes this value:
```{code-cell} ipython3
def W(q, market):
# Unpack
d_0, d_1, s_0, s_1 = market.d_0, market.d_1, market.s_0, market.s_1
d_0, d_1 = market.d_0, market.d_1
s_0, s_1 = market.s_0, market.s_1
# Compute and return welfare
S_c = d_0 * q - d_1 * q**1.6 / 1.6
S_p = s_0 * q + s_1 * q**2.8 / 2.8
Expand Down Expand Up @@ -577,7 +575,7 @@ price, in line with the first fundamental welfare theorem.
```


```{solution-start} isd_ex3
```{solution-start} isd_ex4
:class: dropdown
```

Expand Down