-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for ConsBequestModel and fix typos
Fixed two small errors in WarmGlowPortfolio model and added basic tests.
- Loading branch information
Showing
2 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |