Skip to content

Commit

Permalink
Add tests for ConsBequestModel and fix typos
Browse files Browse the repository at this point in the history
Fixed two small errors in WarmGlowPortfolio model and added basic tests.
  • Loading branch information
mnwhite committed Mar 22, 2024
1 parent 316cb71 commit c5ff3e3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
6 changes: 3 additions & 3 deletions HARK/ConsumptionSaving/ConsBequestModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,13 @@ def __init__(

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

self.warm_glow = UtilityFuncStoneGeary(self.BeqCRRA, self.BeqFac, self.BeqShift)
BeqFacEff = (1.0 - self.LivPrb) * self.BeqFac
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.EndOfPrddvda = self.EndOfPrddvda + self.warm_glow.der(self.aNrm_tiled)
self.EndOfPrddvdaNvrs = self.uPinv(self.EndOfPrddvda)


Expand Down
61 changes: 61 additions & 0 deletions HARK/ConsumptionSaving/tests/test_ConsBequestModel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import unittest
from HARK.tests import HARK_PRECISION
from HARK.ConsumptionSaving.ConsBequestModel import (
BequestWarmGlowConsumerType,
BequestWarmGlowPortfolioType,
)


class testWarmGlowConsumerType(unittest.TestCase):
def setUp(self):
self.agent = BequestWarmGlowConsumerType()
self.agent.vFuncBool = True
self.agent.solve()

def test_solution(self):
cFunc = self.agent.solution[0].cFunc
mNrm = 10.0
self.assertAlmostEqual(cFunc(mNrm).tolist(), 5.56409, places=HARK_PRECISION)

# TODO: Turn this on when solver overhaul branch is merged (needs correct value)
# def test_value(self):
# vFunc = self.agent.solution[0].vFunc
# mNrm = 10.0
# self.assertAlmostEqual(vFunc(mNrm), -0.0000, places=HARK_PRECISION)

def test_simulation(self):
self.agent.T_sim = 10
self.agent.track_vars = ["mNrm", "cNrm", "aNrm"]
self.agent.make_shock_history()
self.agent.initialize_sim()
self.agent.simulate()


class testBequestWarmGlowPortfolioType(unittest.TestCase):
def setUp(self):
self.agent = BequestWarmGlowPortfolioType()
self.agent.vFuncBool = True
self.agent.solve()

def test_consumption(self):
cFunc = self.agent.solution[0].cFuncAdj
mNrm = 10.0
self.assertAlmostEqual(cFunc(mNrm).tolist(), 2.19432, places=HARK_PRECISION)

def test_share(self):
ShareFunc = self.agent.solution[0].ShareFuncAdj
mNrm = 10.0
self.assertAlmostEqual(ShareFunc(mNrm).tolist(), 0.75504, places=HARK_PRECISION)

# TODO: Turn this on when solver overhaul branch is merged (needs correct value)
# def test_value(self):
# vFunc = self.agent.solution[0].vFuncAdj
# mNrm = 10.0
# self.assertAlmostEqual(vFunc(mNrm), -0.0000, places=HARK_PRECISION)

def test_simulation(self):
self.agent.T_sim = 10
self.agent.track_vars = ["mNrm", "cNrm", "aNrm", "Share"]
self.agent.make_shock_history()
self.agent.initialize_sim()
self.agent.simulate()

0 comments on commit c5ff3e3

Please sign in to comment.