Skip to content

Commit

Permalink
Tom's March 20 edit of market.py
Browse files Browse the repository at this point in the history
  • Loading branch information
thomassargent30 committed Mar 20, 2015
1 parent 4511448 commit 8c1ce59
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def consumer_surp(self):

def producer_surp(self):
"Compute producer surplus"
# == Compute area above supply curve, excluding tax == #
# == Compute area above inverse supply curve, excluding tax == #
integrand = lambda x: -(self.az/self.bz) + (1/self.bz) * x
area, error = quad(integrand, 0, self.quantity())
return (self.price() - self.tax) * self.quantity() - area
Expand Down
58 changes: 58 additions & 0 deletions examples/market.py~
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
Filename: market.py
Reference: http://quant-econ.net/py/python_oop.html
"""

from __future__ import division
from scipy.integrate import quad

class Market:

def __init__(self, ad, bd, az, bz, tax):
"""
Set up market parameters. All parameters are scalars. See
http://quant-econ.net/py/python_oop.html for interpretation.

"""
self.ad, self.bd, self.az, self.bz, self.tax = ad, bd, az, bz, tax
if ad < az:
raise ValueError('Insufficient demand.')

def price(self):
"Return equilibrium price"
return (self.ad - self.az + self.bz*self.tax)/(self.bd + self.bz)

def quantity(self):
"Compute equilibrium quantity"
return self.ad - self.bd * self.price()

def consumer_surp(self):
"Compute consumer surplus"
# == Compute area under inverse demand function == #
integrand = lambda x: (self.ad/self.bd) - (1/self.bd)* x
area, error = quad(integrand, 0, self.quantity())
return area - self.price() * self.quantity()

def producer_surp(self):
"Compute producer surplus"
# == Compute area above inverse supply curve, excluding tax == #
integrand = lambda x: -(self.az/self.bz) + (1/self.bz) * x
area, error = quad(integrand, 0, self.quantity())
return (self.price() - self.tax) * self.quantity() - area

def taxrev(self):
"Compute tax revenue"
return self.tax * self.quantity()

def inverse_demand(self,x):
"Compute inverse demand"
return self.ad/self.bd - (1/self.bd)* x

def inverse_supply(self,x):
"Compute inverse supply curve"
return -(self.az/self.bz) + (1/self.bz) * x + self.tax

def inverse_supply_no_tax(self,x):
"Compute inverse supply curve without tax"
return -(self.az/self.bz) + (1/self.bz) * x

0 comments on commit 8c1ce59

Please sign in to comment.