Market Equilibria#
We will now explore the relationship between price and quantity of oranges produced between 1924 and 1938. Since the data [] is from the 1920s and 1930s, it is important to remember that the prices are much lower than what they would be today because of inflation, competition, innovations, and other factors. For example, in 1924, a ton of oranges would have costed $6.63; that same amount in 2019 is $100.78.
fruitprice = Table.read_table('fruitprice.csv')
fruitprice
Year | Pear Price | Pear Unloads (Tons) | Plum Price | Plum Unloads | Peach Price | Peach Unloads | Orange Price | Orange Unloads | NY Factory Wages |
---|---|---|---|---|---|---|---|---|---|
1924 | 8.04 | 18489 | 8.86 | 6582 | 4.96 | 41880 | 6.63 | 21258 | 27.22 |
1925 | 5.67 | 21919 | 7.27 | 5526 | 4.87 | 38772 | 9.19 | 15426 | 28.03 |
1926 | 5.44 | 29328 | 6.68 | 5742 | 3.35 | 46516 | 7.2 | 24762 | 28.89 |
1927 | 7.15 | 17082 | 8.09 | 5758 | 5.7 | 32500 | 8.63 | 22766 | 29.14 |
1928 | 5.81 | 20708 | 7.41 | 6000 | 4.13 | 46820 | 10.71 | 18766 | 29.34 |
1929 | 7.6 | 13071 | 10.86 | 3504 | 6.7 | 36990 | 6.36 | 35702 | 29.97 |
1930 | 5.06 | 22068 | 6.23 | 7998 | 6.35 | 29680 | 10.5 | 23718 | 28.68 |
1931 | 5.4 | 19255 | 6.86 | 5638 | 3.91 | 50940 | 5.81 | 39263 | 26.35 |
1932 | 4.06 | 17293 | 6.09 | 7364 | 4.57 | 27642 | 4.71 | 38553 | 21.98 |
1933 | 4.78 | 11063 | 5.86 | 8136 | 3.57 | 35560 | 4.6 | 36540 | 22.26 |
... (5 rows omitted)
Finding the Equilibrium#
An important concept in econmics is the market equilibrium. This is the point at which the demand and supply curves meet and represents the “optimal” level of production and price in that market.
Definition
The market equilibrium is the price and quantity at which the demand and supply curves intersect. The price and resulting transaction quantity at the equilibrium is what we would predict to observe in the market.
Let’s walk through how to the market equilibrium using the market for oranges as an example.
Data Preprocessing#
Because we are only examining the relationship between prices and quantity for oranges, we can create a new table with the relevant columns: Year
, Orange Price
, and Orange Unloads
. Here, Orange Price
is measured in dollars, while Orange Unloads
is measured in tons.
oranges_raw = fruitprice.select("Year", "Orange Price", "Orange Unloads")
oranges_raw
Year | Orange Price | Orange Unloads |
---|---|---|
1924 | 6.63 | 21258 |
1925 | 9.19 | 15426 |
1926 | 7.2 | 24762 |
1927 | 8.63 | 22766 |
1928 | 10.71 | 18766 |
1929 | 6.36 | 35702 |
1930 | 10.5 | 23718 |
1931 | 5.81 | 39263 |
1932 | 4.71 | 38553 |
1933 | 4.6 | 36540 |
... (5 rows omitted)
Next, we will rename our columns. In this case, let’s rename Orange Unloads
to Quantity
and Orange Price
to Price
for brevity and understandability.
oranges = oranges_raw.relabel("Orange Unloads", "Quantity").relabel("Orange Price", "Price")
oranges
Year | Price | Quantity |
---|---|---|
1924 | 6.63 | 21258 |
1925 | 9.19 | 15426 |
1926 | 7.2 | 24762 |
1927 | 8.63 | 22766 |
1928 | 10.71 | 18766 |
1929 | 6.36 | 35702 |
1930 | 10.5 | 23718 |
1931 | 5.81 | 39263 |
1932 | 4.71 | 38553 |
1933 | 4.6 | 36540 |
... (5 rows omitted)
Visualize the Relationship#
Let’s first take a look to see what the relationship between price and quantity is. We would expect to see a downward-sloping relationship between price and quantity; if a product’s price increases, consumers will purchase less, and if a product’s price decreases, then consumers will purchase more.
We will create a scatterplot between the points.
[Following image is a scatter plot for demand for oranges]
oranges.scatter("Quantity", "Price", width=5, height=5)
plt.title("Demand Curve for Oranges", fontsize = 16);
The visualization shows a negative relationship between quantity and price, which is in line with our expectations: as the price increases, fewer consumers will purchase oranges, so the quantity demanded will decrease. This corresponds to a leftward movement along the demand curve. Alternatively, as the price decreases, the quantity sold will increase because consumers want to maximize their purchasing power and buy more oranges; this is shown by a rightward movement along the curve.
Fit a Polynomial#
We will now quantify our demand curve using NumPy’s np.polyfit
function. Recall that np.polyfit
returns an array of size 2, where the first element is the slope and the second is the \(y\)-intercept.
For this exercise, we will be expressing demand and supply as quantities in terms of price.
np.polyfit(oranges.column("Price"), oranges.column("Quantity"), 1)
array([ -3432.84670093, 53625.8748401 ])
This shows that the demand curve is \(D(P) = -3433 P+ 53626\). The slope is -3433 and \(y\)-intercept is 53626. That means that as price increases by 1 unit (in this case, $1), quantity decreases by 3433 units (in this case, 3433 tons).
Create the Demand Curve#
We will now use SymPy to write out this demand curve. To do so, we start by creating a symbol P
that we can use to create the equation.
P = sympy.Symbol("P")
demand = -3432.846 * P + 53625.87
demand
Create the Supply Curve#
As you’ve learned, the supply curve is the relationship between the price of a good or service and the quantity of that good or service that the seller is willing to supply. It shows how much of a good suppliers are willing and able to supply at different prices. In this case, as the price of the oranges increases, the quantity of oranges that orange manufacturers are willing to supply increases. They capture the producer’s side of market decisions and are upward-sloping.
Let’s now assume that the supply curve is given by \(S(P) = 4348P\). (Note that this supply curve is not based on data.)
supply = 4348 * P
supply
This means that as the price of oranges increases by 1, the quantity supplied increases by 4348. At a price of 0, no oranges are supplied.
Find the Price Equilibrium#
With the supply and demand curves known, we can solve the for equilibrium. The equilibrium is the point where the supply curve and demand curve intersect, and denotes the price and quantity of the good transacted in the market.
The equilbrium consists of 2 components: the quantity equilbrium and price equilbrium. The price equilibrium is the price at which the supply curve and demand curve intersect: the price of the good that consumers desire to purchase at is equivalent to the price of the good that producers want to sell at. There is no shortage of surplus of the product at this price.
Let’s find the price equilibrium. To do this, we will use the provided solve
function. This is a custom function that leverages some SymPy magic and will be provided to you in assignments.
P_star = solve(demand, supply)
P_star
This means that the price of oranges that consumers want to purchase at and producers want to provide is about $6.89.
Find the Quantity Equilibrium#
Similarly, the quantity equilibrium is the quantity of the good that consumers desire to purchase is equivalent to the quantity of the good that producers supply; there is no shortage or surplus of the good at this quantity.
demand.subs(P, P_star)
supply.subs(P, P_star)
This means that the number of tons of oranges that consumers want to purchase and producers want to provide in this market is about 29,967 tons of oranges.
Visualize the Market Equilibrium#
Now that we have our demand and supply curves and price and quantity equilibria, we can visualize them on a graph to see what they look like.
There are 2 pre-made functions we will use: plot_equation
and plot_intercept
.
plot_equation
: It takes in the equation we made previously (either demand or supply) and visualizes the equations between the different prices we give itplot_intercept
: It takes in two different equations (demand and supply), finds the point at which the two intersect, and creates a scatter plot of the result
def plot_equation(equation, price_start, price_end, label=None, color=None, linestyle=None):
plot_prices = [price_start, price_end]
plot_quantities = [equation.subs(list(equation.free_symbols)[0], c) for c in plot_prices]
plt.plot(plot_quantities, plot_prices, label=label, color=color, linestyle=linestyle)
def plot_intercept(eq1, eq2):
ex = sympy.solve(eq1-eq2)[0]
why = eq1.subs(list(eq1.free_symbols)[0], ex)
plt.scatter([why], [ex], zorder=10, color="black")
return (ex, why)
We can leverage these functions and the equations we made earlier to create a graph that shows the market equilibrium.
[Following image is a scatter plot for supply and demand for oranges]
You can also practice on your own and download additional data sets here, courtesy of the University of Flordia’s Statistics Department.
Movements Away from Equilibrium#
What happens to market equilibrium when either supply or demand shifts due to an exogenous shock?
Let’s assume that consumers now prefer Green Tea as their hot beverage of choice moreso than before. We have an outward shift of the demand curve - quantity demanded is greater at every price. The market is no longer in equilibrium.
[Following image is a hand drawn diagram of a shift in demand]
At the same price level (the former equilibrium price), there is a shortage of Green Tea. The amount demanded by consumers exceeds that supplied by producers: \(Q_D > Q_S\). This is a seller’s market, as the excess quantity demanded gives producers leverage (or market power) over consumers. They are able to increase the price of Green Tea to clear the shortage. As prices increase, consumers who were willing and able to purchase tea at the previous equilibrium price would leave the market, reducing quantity demanded. \(Q_S\) and \(Q_D\) move up along their respective curves until the new equilibrium is achieved where \(Q_S = Q_D\).
This dual effect of increasing \(Q_S\) and \(Q_D\) is sometimes referred to as the “invisible hand”. Sans government intervention, it clears out the shortage or surplus in the market, resulting in the eventual convergence to a new equilibrium level of quantity \(Q^*\) and price \(P^*\).