-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from alexanderthclark/eqm
Add equilibrium class
- Loading branch information
Showing
3 changed files
with
80 additions
and
13 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from microecon.curves import Demand, Supply, intersection | ||
|
||
class Equilibrium: | ||
|
||
def __init__ (self, demand: Demand, supply: Supply): | ||
"""Equilibrium produced by demand and supply. Initialized as market equilibrium.""" | ||
|
||
self.demand = demand | ||
self.supply = supply | ||
for dpiece in demand.pieces: | ||
for spiece in supply.pieces: | ||
if dpiece and spiece: | ||
s_domain = spiece._domain | ||
d_domain = dpiece._domain | ||
p, q = intersection(dpiece, spiece) | ||
in_demand = d_domain[1] <= q <= d_domain[0] | ||
in_supply = s_domain[0] <= q <= s_domain[1] | ||
if in_demand and in_supply: | ||
self.q = q | ||
self.p = p | ||
break | ||
|
||
def plot(self): | ||
|
||
q_int = np.max([piece.q_intercept for piece in self.demand.pieces if piece]) | ||
|
||
fig, ax = plt.subplots() | ||
self.demand.plot(ax=ax) | ||
self.supply.plot(ax=ax, max_q=q_int) |