Skip to content

Commit

Permalink
Cobb Douglas utilities for Durables
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlujan91 committed Nov 23, 2023
1 parent 37c25a7 commit d36b094
Showing 1 changed file with 41 additions and 29 deletions.
70 changes: 41 additions & 29 deletions HARK/rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,35 +911,36 @@ class UtilityFuncCobbDouglas(UtilityFunction):
Parameters
----------
EOS : float
The coefficient for elasticity of substitution.
factor : float
Factor productivity parameter. (e.g. TFP in production function)
c_share : float
Share parameter for consumption. Must be between 0 and 1.
d_bar : float
Intercept parameter for durable consumption. Must be non-negative.
"""

distance_criteria = ["EOS", "factor"]

def __init__(self, EOS, factor=1.0):
self.EOS = np.asarray(EOS)
self.factor = factor
distance_criteria = ["c_share", "d_bar"]

assert np.isclose(np.sum(self.EOS), 1.0), """The sum of the elasticity of substitution
parameters must be less than or equal to 1."""
def __init__(self, c_share, d_bar=0):
self.c_share = c_share
self.d_bar = d_bar

Check warning on line 924 in HARK/rewards.py

View check run for this annotation

Codecov / codecov/patch

HARK/rewards.py#L923-L924

Added lines #L923 - L924 were not covered by tests

assert factor > 0, "Factor must be positive."
assert 0 <= c_share <= 1, "Share parameter must be between 0 and 1."

Check warning on line 926 in HARK/rewards.py

View check run for this annotation

Codecov / codecov/patch

HARK/rewards.py#L926

Added line #L926 was not covered by tests

self.dim = len(self.EOS) # number of goods

def __call__(self, x):
def __call__(self, c, d):
"""
Evaluate the utility function at a given level of consumption c.
"""
assert self.EOS.size == x.shape[-1], "x must be compatible with EOS"
cobb_douglas(x, self.EOS, self.factor)
return CDutility(c, d, self.c_share, self.d_bar)

Check warning on line 932 in HARK/rewards.py

View check run for this annotation

Codecov / codecov/patch

HARK/rewards.py#L932

Added line #L932 was not covered by tests

def derivative(self, c, d, axis=0):
if axis == 0:
return CDutilityPc(c, d, self.c_share, self.d_bar)
elif axis == 1:
return CDutilityPd(c, d, self.c_share, self.d_bar)

Check warning on line 938 in HARK/rewards.py

View check run for this annotation

Codecov / codecov/patch

HARK/rewards.py#L935-L938

Added lines #L935 - L938 were not covered by tests
else:
raise ValueError(f"Axis must be 0 or 1, not {axis}")

Check warning on line 940 in HARK/rewards.py

View check run for this annotation

Codecov / codecov/patch

HARK/rewards.py#L940

Added line #L940 was not covered by tests

def derivative(self, x, args=()):
assert self.EOS.size == x.shape[-1], "x must be compatible with EOS"
return cobb_douglas_pn(x, self.EOS, self.factor, args)
def inverse(self, uc, d):
return CDutilityPc_inv(uc, d, self.c_share, self.d_bar)

Check warning on line 943 in HARK/rewards.py

View check run for this annotation

Codecov / codecov/patch

HARK/rewards.py#L943

Added line #L943 was not covered by tests


class UtilityFuncCobbDouglasCRRA(UtilityFuncCobbDouglas):
Expand All @@ -950,22 +951,33 @@ class UtilityFuncCobbDouglasCRRA(UtilityFuncCobbDouglas):
Parameters
----------
EOS : float
The coefficient for elasticity of substitution.
factor : float
Factor productivity parameter. (e.g. TFP in production function)
c_share : float
Share parameter for consumption. Must be between 0 and 1.
d_bar : float
Intercept parameter for durable consumption. Must be non-negative.
CRRA: float
Coefficient of relative risk aversion.
"""

distance_criteria = ["EOS", "factor", "CRRA"]
distance_criteria = ["c_share", "d_bar", "CRRA"]

def __init__(self, EOS, factor, CRRA):
super().__init__(EOS, factor)
def __init__(self, c_share, CRRA, d_bar=0):
super().__init__(c_share, d_bar)

Check warning on line 965 in HARK/rewards.py

View check run for this annotation

Codecov / codecov/patch

HARK/rewards.py#L965

Added line #L965 was not covered by tests
self.CRRA = CRRA

def __call__(self, x):
return CRRAutility(cobb_douglas(x, self.EOS, self.factor), self.CRRA)
def __call__(self, c, d):
return CRRACDutility(c, d, self.c_share, self.d_bar, self.CRRA)

Check warning on line 969 in HARK/rewards.py

View check run for this annotation

Codecov / codecov/patch

HARK/rewards.py#L969

Added line #L969 was not covered by tests

def derivative(self, c, d, axis=0):
if axis == 0:
return CRRACDutilityPc(c, d, self.c_share, self.d_bar, self.CRRA)
elif axis == 1:
return CRRACDutilityPd(c, d, self.c_share, self.d_bar, self.CRRA)

Check warning on line 975 in HARK/rewards.py

View check run for this annotation

Codecov / codecov/patch

HARK/rewards.py#L972-L975

Added lines #L972 - L975 were not covered by tests
else:
raise ValueError(f"Axis must be 0 or 1, not {axis}")

Check warning on line 977 in HARK/rewards.py

View check run for this annotation

Codecov / codecov/patch

HARK/rewards.py#L977

Added line #L977 was not covered by tests

def inverse(self, uc, d):
return CRRACDutilityPc_inv(uc, d, self.c_share, self.d_bar, self.CRRA)

Check warning on line 980 in HARK/rewards.py

View check run for this annotation

Codecov / codecov/patch

HARK/rewards.py#L980

Added line #L980 was not covered by tests


class UtilityFuncConstElastSubs(UtilityFunction):
Expand Down

0 comments on commit d36b094

Please sign in to comment.