Skip to content

Commit

Permalink
Value function works for ConsRiskyAsset
Browse files Browse the repository at this point in the history
It was trying to use broken values before.
  • Loading branch information
mnwhite committed Mar 15, 2024
1 parent 8b759b4 commit 0a94ca7
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions HARK/ConsumptionSaving/ConsRiskyAssetModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,8 @@ def calc_vPPnext(S, a):
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))
vNvrsFuncNow = CubicInterp(
mNrm_temp, vNvrs_temp, vNvrsP_temp, MPCminNvrs * hNrmNow, MPCminNvrs
)
# MPCminNvrs = MPCminNow ** (-CRRA / (1.0 - CRRA))
vNvrsFuncNow = CubicInterp(mNrm_temp, vNvrs_temp, vNvrsP_temp)
vFuncNow = ValueFuncCRRA(vNvrsFuncNow, CRRA)
else:
vFuncNow = NullFunc() # Dummy object
Expand Down Expand Up @@ -1129,6 +1127,48 @@ def v_next(shocks, a_nrm):
self.ShockDstn, v_next, self.aNrmNow
)

def make_vFunc(self, solution):
"""
Creates the value function for this period, defined over market resources m.
self must have the attribute EndOfPrdvFunc in order to execute.
Parameters
----------
solution : ConsumerSolution
The solution to this single period problem, which must include the
consumption function.
Returns
-------
vFuncNow : ValueFuncCRRA
A representation of the value function for this period, defined over
normalized market resources m: v = vFuncNow(m).
"""
# Compute expected value and marginal value on a grid of market resources
mNrm_temp = self.mNrmMinNow + self.aXtraGrid
cNrmNow = solution.cFunc(mNrm_temp)
aNrmNow = mNrm_temp - cNrmNow
vNrmNow = self.u(cNrmNow) + self.EndOfPrdvFunc(aNrmNow)
vPnow = self.u.der(cNrmNow)

# Construct the beginning-of-period value function
# value transformed through inverse utility
vNvrs = self.u.inv(vNrmNow)
vNvrsP = vPnow * self.u.derinv(vNrmNow, order=(0, 1))
mNrm_temp = np.insert(mNrm_temp, 0, self.mNrmMinNow)
vNvrs = np.insert(vNvrs, 0, 0.0)
vNvrsP = np.insert(
vNvrsP, 0, self.MPCmaxEff ** (-self.CRRA / (1.0 - self.CRRA))
)
# MPCminNvrs = self.MPCminNow ** (-self.CRRA / (1.0 - self.CRRA))
vNvrsFuncNow = CubicInterp(
mNrm_temp,
vNvrs,
vNvrsP,
)
vFuncNow = ValueFuncCRRA(vNvrsFuncNow, self.CRRA)
return vFuncNow


@dataclass
class ConsPortfolioIndShkRiskyAssetSolver(ConsIndShkRiskyAssetSolver):
Expand Down

0 comments on commit 0a94ca7

Please sign in to comment.