Skip to content

Commit

Permalink
Begin moving OO solvers out of model files
Browse files Browse the repository at this point in the history
Had to move one very small agent type into its own file. It looks like it's a PortfolioConsumerType with a slightly different solver.
  • Loading branch information
mnwhite committed Mar 22, 2024
1 parent ccf9c8a commit 561872e
Show file tree
Hide file tree
Showing 7 changed files with 3,015 additions and 3,007 deletions.
133 changes: 0 additions & 133 deletions HARK/ConsumptionSaving/ConsBequestModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
import numpy as np
from HARK import NullFunc
from HARK.ConsumptionSaving.ConsIndShockModel import (
ConsIndShockSolver,
ConsumerSolution,
IndShockConsumerType,
init_idiosyncratic_shocks,
init_lifecycle,
)
from HARK.ConsumptionSaving.ConsPortfolioModel import (
ConsPortfolioSolver,
PortfolioConsumerType,
PortfolioSolution,
init_portfolio,
Expand Down Expand Up @@ -988,137 +986,6 @@ def calc_EndOfPrd_v(S, a, z):
return solution_now


class BequestWarmGlowConsumerSolver(ConsIndShockSolver):
def __init__(
self,
solution_next,
IncShkDstn,
LivPrb,
DiscFac,
CRRA,
Rfree,
PermGroFac,
BoroCnstArt,
aXtraGrid,
BeqCRRA,
BeqFac,
BeqShift,
):
self.BeqCRRA = BeqCRRA
self.BeqFac = BeqFac
self.BeqShift = BeqShift
vFuncBool = False
CubicBool = False

super().__init__(
solution_next,
IncShkDstn,
LivPrb,
DiscFac,
CRRA,
Rfree,
PermGroFac,
BoroCnstArt,
aXtraGrid,
vFuncBool,
CubicBool,
)

def def_utility_funcs(self):
super().def_utility_funcs()

BeqFacEff = (1.0 - self.LivPrb) * self.BeqFac

self.warm_glow = UtilityFuncStoneGeary(self.BeqCRRA, BeqFacEff, self.BeqShift)

def def_BoroCnst(self, BoroCnstArt):
self.BoroCnstNat = (
(self.solution_next.mNrmMin - self.TranShkMinNext)
* (self.PermGroFac * self.PermShkMinNext)
/ self.Rfree
)

self.BoroCnstNat = np.max([self.BoroCnstNat, -self.BeqShift])

if BoroCnstArt is None:
self.mNrmMinNow = self.BoroCnstNat
else:
self.mNrmMinNow = np.max([self.BoroCnstNat, BoroCnstArt])
if self.BoroCnstNat < self.mNrmMinNow:
self.MPCmaxEff = 1.0
else:
self.MPCmaxEff = self.MPCmaxNow

self.cFuncNowCnst = LinearInterp(
np.array([self.mNrmMinNow, self.mNrmMinNow + 1]), np.array([0.0, 1.0])
)

def calc_EndOfPrdvP(self):
EndofPrdvP = super().calc_EndOfPrdvP()

return EndofPrdvP + self.warm_glow.der(self.aNrmNow)


class BequestWarmGlowPortfolioSolver(ConsPortfolioSolver):
def __init__(
self,
solution_next,
ShockDstn,
IncShkDstn,
RiskyDstn,
LivPrb,
DiscFac,
CRRA,
Rfree,
PermGroFac,
BoroCnstArt,
aXtraGrid,
ShareGrid,
AdjustPrb,
ShareLimit,
BeqCRRA,
BeqFac,
BeqShift,
):
self.BeqCRRA = BeqCRRA
self.BeqFac = BeqFac
self.BeqShift = BeqShift
vFuncBool = False
DiscreteShareBool = False
IndepDstnBool = True

super().__init__(
solution_next,
ShockDstn,
IncShkDstn,
RiskyDstn,
LivPrb,
DiscFac,
CRRA,
Rfree,
PermGroFac,
BoroCnstArt,
aXtraGrid,
ShareGrid,
vFuncBool,
AdjustPrb,
DiscreteShareBool,
ShareLimit,
IndepDstnBool,
)

def def_utility_funcs(self):
super().def_utility_funcs()
BeqFacEff = (1.0 - self.LivPrb) * self.BeqFac # "effective" beq factor
self.warm_glow = UtilityFuncStoneGeary(self.BeqCRRA, BeqFacEff, self.BeqShift)

def calc_EndOfPrdvP(self):
super().calc_EndOfPrdvP()

self.EndOfPrddvda = self.EndOfPrddvda + self.warm_glow.der(self.aNrm_tiled)
self.EndOfPrddvdaNvrs = self.uPinv(self.EndOfPrddvda)


init_wealth_in_utility = init_idiosyncratic_shocks.copy()
init_wealth_in_utility["BeqCRRA"] = init_idiosyncratic_shocks["CRRA"]
init_wealth_in_utility["BeqFac"] = 1.0
Expand Down
Loading

0 comments on commit 561872e

Please sign in to comment.