Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions HARK/ConsumptionSaving/ConsBequestModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
MargValueFuncCRRA,
ValueFuncCRRA,
)
from HARK.rewards import UtilityFuncCRRA, UtilityFuncStoneGeary
from HARK.rewards import UtilityFuncCRRA, UtilityFuncStoneGeary, vNvrsSlope
from HARK.utilities import make_assets_grid


Expand Down Expand Up @@ -416,8 +416,8 @@ def calc_vPPnext(S, a, R):
vNvrsP_temp = vP_temp * uFunc.derinv(v_temp, order=(0, 1))
mNrm_temp = np.insert(mNrm_temp, 0, mNrmMinNow)
vNvrs_temp = np.insert(vNvrs_temp, 0, 0.0)
vNvrsP_temp = np.insert(vNvrsP_temp, 0, MPCmaxEff ** (-CRRA / (1.0 - CRRA)))
MPCminNvrs = MPCminNow ** (-CRRA / (1.0 - CRRA))
vNvrsP_temp = np.insert(vNvrsP_temp, 0, vNvrsSlope(MPCmaxEff, CRRA))
MPCminNvrs = vNvrsSlope(MPCminNow, CRRA)
vNvrsFuncNow = CubicInterp(
mNrm_temp, vNvrs_temp, vNvrsP_temp, MPCminNvrs * hNrmNow, MPCminNvrs
)
Expand Down
3 changes: 2 additions & 1 deletion HARK/ConsumptionSaving/ConsGenIncProcessModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
CRRAutilityP_invP,
CRRAutilityPP,
UtilityFuncCRRA,
vNvrsSlope,
)
from HARK.utilities import make_assets_grid

Expand Down Expand Up @@ -486,7 +487,7 @@ def calc_vPP_next(S, a, p):
)

# Add data at the lower bound of p
MPCminNvrs = MPCminNow ** (-CRRA / (1.0 - CRRA))
MPCminNvrs = vNvrsSlope(MPCminNow, CRRA)
m_temp = np.reshape(mLvl_temp[:, 0], (aNrmCount + 1, 1))
mLvl_temp = np.concatenate((m_temp, mLvl_temp), axis=1)
vNvrs_temp = np.concatenate((MPCminNvrs * m_temp, vNvrs_temp), axis=1)
Expand Down
11 changes: 6 additions & 5 deletions HARK/ConsumptionSaving/ConsIndShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
CRRAutilityP_invP,
CRRAutilityPP,
UtilityFuncCRRA,
vNvrsSlope,
)
from HARK.utilities import make_assets_grid
from scipy.optimize import newton
Expand Down Expand Up @@ -373,7 +374,7 @@ def solve_one_period_ConsPF(
# Calculate (pseudo-inverse) value at each consumption kink point
vNow = uFunc(cNrmNow) + EndOfPrdv
vNvrsNow = uFunc.inverse(vNow)
vNvrsSlopeMin = MPCminNow ** (-CRRA / (1.0 - CRRA))
vNvrsSlopeMin = vNvrsSlope(MPCminNow, CRRA)

# Add an additional point to the list of gridpoints for the extrapolation,
# using the new value of the lower bound of the MPC.
Expand Down Expand Up @@ -786,8 +787,8 @@ def solve_one_period_ConsIndShock(
vNvrsP_temp = vP_temp * uFunc.derinv(v_temp, order=(0, 1))
mNrm_temp = np.insert(mNrm_temp, 0, mNrmMinNow)
vNvrs_temp = np.insert(vNvrs_temp, 0, 0.0)
vNvrsP_temp = np.insert(vNvrsP_temp, 0, MPCmaxNow ** (-CRRA / (1.0 - CRRA)))
MPCminNvrs = MPCminNow ** (-CRRA / (1.0 - CRRA))
vNvrsP_temp = np.insert(vNvrsP_temp, 0, vNvrsSlope(MPCmaxNow, CRRA))
MPCminNvrs = vNvrsSlope(MPCminNow, CRRA)
vNvrsFuncNow = CubicInterp(
mNrm_temp,
vNvrs_temp,
Expand Down Expand Up @@ -1052,8 +1053,8 @@ def solve_one_period_ConsKinkedR(
vNvrsP_temp = vP_temp * uFunc.derinv(v_temp, order=(0, 1))
mNrm_temp = np.insert(mNrm_temp, 0, mNrmMinNow)
vNvrs_temp = np.insert(vNvrs_temp, 0, 0.0)
vNvrsP_temp = np.insert(vNvrsP_temp, 0, MPCmaxNow ** (-CRRA / (1.0 - CRRA)))
MPCminNvrs = MPCminNow ** (-CRRA / (1.0 - CRRA))
vNvrsP_temp = np.insert(vNvrsP_temp, 0, vNvrsSlope(MPCmaxNow, CRRA))
MPCminNvrs = vNvrsSlope(MPCminNow, CRRA)
vNvrsFuncNow = CubicInterp(
mNrm_temp,
vNvrs_temp,
Expand Down
7 changes: 4 additions & 3 deletions HARK/ConsumptionSaving/ConsIndShockModelFast.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
CRRAutility_invP,
CRRAutilityP,
CRRAutilityP_inv,
vNvrsSlope,
CRRAutilityP_invP,
CRRAutilityPP,
cubic_interp_fast,
Expand Down Expand Up @@ -405,7 +406,7 @@ def _solveConsPerfForesightNumba(
mNrmMinNow = mNrmNow[0]

# See the PerfForesightConsumerType.ipynb documentation notebook for the derivations
vFuncNvrsSlope = MPCmin ** (-CRRA / (1.0 - CRRA))
vFuncNvrsSlope = vNvrsSlope(MPCmin, CRRA)

return (
mNrmNow,
Expand Down Expand Up @@ -936,8 +937,8 @@ def _add_vFuncNumba(
vNvrsP = vPnow * utility_invP(vNrmNow, CRRA)
mNrmGrid = _np_insert(mNrmGrid, 0, mNrmMinNow)
vNvrs = _np_insert(vNvrs, 0, 0.0)
vNvrsP = _np_insert(vNvrsP, 0, MPCmaxEff ** (-CRRA / (1.0 - CRRA)))
MPCminNvrs = MPCminNow ** (-CRRA / (1.0 - CRRA))
vNvrsP = _np_insert(vNvrsP, 0, vNvrsSlope(MPCmaxEff, CRRA))
MPCminNvrs = vNvrsSlope(MPCminNow, CRRA)

return (
mNrmGrid,
Expand Down
7 changes: 3 additions & 4 deletions HARK/ConsumptionSaving/ConsMarkovModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
CRRAutilityP_inv,
CRRAutilityP_invP,
CRRAutilityPP,
vNvrsSlope,
)
from HARK.utilities import make_assets_grid

Expand Down Expand Up @@ -640,10 +641,8 @@ def calc_vPPnext(S, a, R):
vNvrsP_now = vP_now * uFunc.derinv(v_now, order=(0, 1))
mNrm_temp = np.insert(mNrm_for_vFunc, 0, mNrmMin_i) # add the lower bound
vNvrs_now = np.insert(vNvrs_now, 0, 0.0)
vNvrsP_now = np.insert(
vNvrsP_now, 0, MPCmaxEff[i] ** (-CRRA / (1.0 - CRRA))
)
# MPCminNvrs = MPCminNow[i] ** (-CRRA / (1.0 - CRRA))
vNvrsP_now = np.insert(vNvrsP_now, 0, vNvrsSlope(MPCmaxEff[i], CRRA))
# MPCminNvrs = vNvrsSlope(MPCminNow[i], CRRA)
vNvrsFuncNow = LinearInterp(
mNrm_temp,
vNvrs_now,
Expand Down
10 changes: 5 additions & 5 deletions HARK/ConsumptionSaving/ConsPrefShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
MargMargValueFuncCRRA,
ValueFuncCRRA,
)
from HARK.rewards import UtilityFuncCRRA
from HARK.rewards import UtilityFuncCRRA, vNvrsSlope

__all__ = [
"PrefShockConsumerType",
Expand Down Expand Up @@ -376,8 +376,8 @@ def calc_vPPnext(S, a, R):
vNvrsP_temp = vP_temp * uFunc.derinv(v_temp, order=(0, 1))
mNrm_temp = np.insert(mNrm_temp, 0, mNrmMinNow)
vNvrs_temp = np.insert(vNvrs_temp, 0, 0.0)
vNvrsP_temp = np.insert(vNvrsP_temp, 0, MPCmaxEff ** (-CRRA / (1.0 - CRRA)))
MPCminNvrs = MPCminNow ** (-CRRA / (1.0 - CRRA))
vNvrsP_temp = np.insert(vNvrsP_temp, 0, vNvrsSlope(MPCmaxEff, CRRA))
MPCminNvrs = vNvrsSlope(MPCminNow, CRRA)
vNvrsFuncNow = CubicInterp(
mNrm_temp, vNvrs_temp, vNvrsP_temp, MPCminNvrs * hNrmNow, MPCminNvrs
)
Expand Down Expand Up @@ -683,8 +683,8 @@ def calc_vPPnext(S, a, R):
vNvrsP_temp = vP_temp * uFunc.derinv(v_temp, order=(0, 1))
mNrm_temp = np.insert(mNrm_temp, 0, mNrmMinNow)
vNvrs_temp = np.insert(vNvrs_temp, 0, 0.0)
vNvrsP_temp = np.insert(vNvrsP_temp, 0, MPCmaxEff ** (-CRRA / (1.0 - CRRA)))
MPCminNvrs = MPCminNow ** (-CRRA / (1.0 - CRRA))
vNvrsP_temp = np.insert(vNvrsP_temp, 0, vNvrsSlope(MPCmaxEff, CRRA))
MPCminNvrs = vNvrsSlope(MPCminNow, CRRA)
vNvrsFuncNow = CubicInterp(
mNrm_temp, vNvrs_temp, vNvrsP_temp, MPCminNvrs * hNrmNow, MPCminNvrs
)
Expand Down
6 changes: 3 additions & 3 deletions HARK/ConsumptionSaving/ConsRiskyAssetModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
MargValueFuncCRRA,
ValueFuncCRRA,
)
from HARK.rewards import UtilityFuncCRRA
from HARK.rewards import UtilityFuncCRRA, vNvrsSlope
from HARK.utilities import make_assets_grid

###############################################################################
Expand Down Expand Up @@ -1557,8 +1557,8 @@ def calc_vPPnext(S, a):
vNvrsP_temp = vP_temp * uFunc.derinv(v_temp, order=(0, 1))
mNrm_temp = np.insert(mNrm_temp, 0, mNrmMinNow)
vNvrs_temp = np.insert(vNvrs_temp, 0, 0.0)
vNvrsP_temp = np.insert(vNvrsP_temp, 0, MPCmaxEff ** (-CRRA / (1.0 - CRRA)))
# MPCminNvrs = MPCminNow ** (-CRRA / (1.0 - CRRA))
vNvrsP_temp = np.insert(vNvrsP_temp, 0, vNvrsSlope(MPCmaxEff, CRRA))
# MPCminNvrs = vNvrsSlope(MPCminNow, CRRA)
vNvrsFuncNow = CubicInterp(mNrm_temp, vNvrs_temp, vNvrsP_temp)
vFuncNow = ValueFuncCRRA(vNvrsFuncNow, CRRA)
else:
Expand Down
19 changes: 7 additions & 12 deletions HARK/ConsumptionSaving/ConsWealthPortfolioModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,13 @@
make_lognormal_kNrm_init_dstn,
make_lognormal_pLvl_init_dstn,
)
from HARK.rewards import UtilityFuncCRRA
from HARK.rewards import (
UtilityFuncCRRA,
CRRAWealthUtilityP,
)
from HARK.utilities import NullFunc, make_assets_grid


def utility(c, a, CRRA, share=0.0, intercept=0.0):
w = a + intercept
return (c ** (1 - share) * w**share) ** (1 - CRRA) / (1 - CRRA)


def dudc(c, a, CRRA, share=0.0, intercept=0.0):
u = utility(c, a, CRRA, share, intercept)
return u * (1 - CRRA) * (1 - share) / c


def calc_m_nrm_next(shocks, b_nrm, perm_gro_fac):
"""
Calculate future realizations of market resources mNrm from the income
Expand Down Expand Up @@ -299,7 +292,9 @@ def solve_one_period_WealthPortfolio(
cNrm_now = np.insert(cNrm_now, 0, 0.0)
cFuncNow = LinearInterp(mNrm_now, cNrm_now)

dudc_now = dudc(cNrm_now, mNrm_now - cNrm_now, CRRA, WealthShare, WealthShift)
dudc_now = CRRAWealthUtilityP(
cNrm_now, mNrm_now - cNrm_now, CRRA, WealthShare, WealthShift
)
dudc_nvrs_now = uFunc.derinv(dudc_now, order=(1, 0))
dudc_nvrs_func_now = LinearInterp(mNrm_now, dudc_nvrs_now)

Expand Down
21 changes: 8 additions & 13 deletions HARK/ConsumptionSaving/ConsWealthUtilityModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@
from HARK.ConsumptionSaving.ConsGenIncProcessModel import (
GenIncProcessConsumerType,
)
from HARK.rewards import UtilityFuncCRRA, CRRAutility
from HARK.rewards import (
UtilityFuncCRRA,
CRRAutility,
CRRAWealthUtility,
CRRAWealthUtilityP,
)
from HARK.utilities import NullFunc, make_assets_grid


Expand Down Expand Up @@ -218,16 +223,6 @@ def make_ChiFromOmega_function(CRRA, WealthShare, ChiFromOmega_N, ChiFromOmega_b
)


def utility(c, a, CRRA, share=0.0, intercept=0.0):
w = a + intercept
return (c ** (1 - share) * w**share) ** (1 - CRRA) / (1 - CRRA)


def dudc(c, a, CRRA, share=0.0, intercept=0.0):
u = utility(c, a, CRRA, share, intercept)
return u * (1 - CRRA) * (1 - share) / c


def calc_m_nrm_next(shocks, a_nrm, G, R):
"""
Calculate future realizations of market resources mNrm from the income
Expand Down Expand Up @@ -371,7 +366,7 @@ def solve_one_period_WealthUtility(
m_temp = aXtraGrid.copy() + mNrmMinNow
c_temp = cFuncNow(m_temp)
a_temp = m_temp - c_temp
dudc_now = dudc(c_temp, a_temp, CRRA, WealthShare, WealthShift)
dudc_now = CRRAWealthUtilityP(c_temp, a_temp, CRRA, WealthShare, WealthShift)
dudc_nvrs_now = np.insert(uFunc.derinv(dudc_now, order=(1, 0)), 0, 0.0)
dudc_nvrs_func_now = LinearInterp(np.insert(m_temp, 0, mNrmMinNow), dudc_nvrs_now)

Expand All @@ -384,7 +379,7 @@ def solve_one_period_WealthUtility(
calc_v_next, IncShkDstn, args=(a_temp, PermGroFac, Rfree, CRRA, vFuncNext)
)
EndOfPrd_v *= DiscFacEff
u_now = utility(c_temp, a_temp, CRRA, WealthShare, WealthShift)
u_now = CRRAWealthUtility(c_temp, a_temp, CRRA, WealthShare, WealthShift)
v_now = u_now + EndOfPrd_v
vNvrs_now = np.insert(uFunc.inverse(v_now), 0, 0.0)
vNvrsFunc = LinearInterp(np.insert(m_temp, 0, mNrmMinNow), vNvrs_now)
Expand Down
5 changes: 3 additions & 2 deletions HARK/models/consumer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from HARK.distributions import Bernoulli, Lognormal, MeanOneLogNormal
from HARK.model import Control, DBlock, RBlock
from HARK.rewards import CRRAutility

"""
Blocks for consumption saving problem (not normalized)
Expand Down Expand Up @@ -35,7 +36,7 @@
"p": lambda PermGroFac, p: PermGroFac * p,
"a": lambda m, c: m - c,
},
"reward": {"u": lambda c, CRRA: c ** (1 - CRRA) / (1 - CRRA)},
"reward": {"u": lambda c, CRRA: CRRAutility(c, CRRA)},
}
)

Expand All @@ -52,7 +53,7 @@
"c": Control(["m"]),
"a": "m - c",
},
"reward": {"u": lambda c, CRRA: c ** (1 - CRRA) / (1 - CRRA)},
"reward": {"u": lambda c, CRRA: CRRAutility(c, CRRA)},
}
)

Expand Down
2 changes: 2 additions & 0 deletions HARK/models/consumer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ blocks:
a: m - c

reward:
# Note: This formula does not support CRRA=1 (log utility).
# For CRRA=1, use the Python solvers which handle this case.
u: c ** (1 - CRRA) / (1 - CRRA)
- &portfolio_choice
name: portfolio choice
Expand Down
3 changes: 2 additions & 1 deletion HARK/models/fisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from HARK.model import Control, DBlock
from HARK.rewards import CRRAutility

# This way of distributing parameters across the scope is clunky
# Can be handled better if parsed from a YAML file, probably
Expand All @@ -25,6 +26,6 @@
"c": Control(["m"]),
"a": lambda m, c: m - c,
},
"reward": {"u": lambda c: c ** (1 - CRRA) / (1 - CRRA)},
"reward": {"u": lambda c: CRRAutility(c, CRRA)},
}
)
3 changes: 2 additions & 1 deletion HARK/models/perfect_foresight.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from HARK.distributions import Bernoulli
from HARK.model import Control, DBlock
from HARK.rewards import CRRAutility

# This way of distributing parameters across the scope is clunky
# Can be handled better if parsed from a YAML file, probably
Expand Down Expand Up @@ -28,6 +29,6 @@
"p": lambda PermGroFac, p: PermGroFac * p,
"a": lambda m, c: m - c,
},
"reward": {"u": lambda c, CRRA: c ** (1 - CRRA) / (1 - CRRA)},
"reward": {"u": lambda c, CRRA: CRRAutility(c, CRRA)},
}
)
3 changes: 2 additions & 1 deletion HARK/models/perfect_foresight_normalized.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from HARK.distributions import Bernoulli
from HARK.model import Control, DBlock
from HARK.rewards import CRRAutility

# This way of distributing parameters across the scope is clunky
# Can be handled better if parsed from a YAML file, probably
Expand Down Expand Up @@ -29,6 +30,6 @@
"c_nrm": Control(["m_nrm"]),
"a_nrm": lambda m_nrm, c_nrm: m_nrm - c_nrm,
},
"reward": {"u": lambda c: c ** (1 - CRRA) / (1 - CRRA)},
"reward": {"u": lambda c: CRRAutility(c, CRRA)},
}
)
2 changes: 2 additions & 0 deletions HARK/numba_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CRRAutilityP_inv,
CRRAutilityP_invP,
CRRAutilityPP_X,
vNvrsSlope as vNvrsSlope_py,
)

CRRAutility = njit(CRRAutility_X, cache=True)
Expand All @@ -18,6 +19,7 @@
CRRAutility_invP = njit(CRRAutility_invP, cache=True)
CRRAutility_inv = njit(CRRAutility_inv, cache=True)
CRRAutilityP_invP = njit(CRRAutilityP_invP, cache=True)
vNvrsSlope = njit(vNvrsSlope_py, cache=True)


@njit(cache=True, error_model="numpy")
Expand Down
Loading