def test_getShocks(self): agent = IndShockConsumerType( AgentCount = 2, T_sim = 10 ) agent.solve() agent.initializeSim() agent.simBirth(np.array([True,False])) agent.simOnePeriod() agent.simBirth(np.array([False,True])) agent.getShocks() self.assertEqual(agent.PermShkNow[0], 1.0050166461586711) self.assertEqual(agent.PermShkNow[1], 1.0050166461586711) self.assertEqual(agent.TranShkNow[0], 1.1176912196531754)
class testIndShockConsumerType(unittest.TestCase): def setUp(self): self.agent = IndShockConsumerType(AgentCount=2, T_sim=10) self.agent.solve() def test_getShocks(self): self.agent.initializeSim() self.agent.simBirth(np.array([True, False])) self.agent.simOnePeriod() self.agent.simBirth(np.array([False, True])) self.agent.getShocks() self.assertEqual(self.agent.shocks["PermShkNow"][0], 1.0427376294215103) self.assertEqual(self.agent.shocks["PermShkNow"][1], 0.9278094171517413) self.assertEqual(self.agent.shocks["TranShkNow"][0], 0.881761797501595) def test_ConsIndShockSolverBasic(self): LifecycleExample = IndShockConsumerType(**init_lifecycle) LifecycleExample.cycles = 1 LifecycleExample.solve() # test the solution_terminal self.assertAlmostEqual(LifecycleExample.solution[10].cFunc(2).tolist(), 2) self.assertAlmostEqual(LifecycleExample.solution[9].cFunc(1), 0.97769632) self.assertAlmostEqual(LifecycleExample.solution[8].cFunc(1), 0.96624445) self.assertAlmostEqual(LifecycleExample.solution[7].cFunc(1), 0.95691449) self.assertAlmostEqual(LifecycleExample.solution[0].cFunc(1).tolist(), 0.87362789) self.assertAlmostEqual(LifecycleExample.solution[1].cFunc(1).tolist(), 0.9081621) self.assertAlmostEqual(LifecycleExample.solution[2].cFunc(1).tolist(), 0.9563899) solver = ConsIndShockSolverBasic( LifecycleExample.solution[1], LifecycleExample.IncomeDstn[0], LifecycleExample.LivPrb[0], LifecycleExample.DiscFac, LifecycleExample.CRRA, LifecycleExample.Rfree, LifecycleExample.PermGroFac[0], LifecycleExample.BoroCnstArt, LifecycleExample.aXtraGrid, LifecycleExample.vFuncBool, LifecycleExample.CubicBool, ) solver.prepareToSolve() self.assertAlmostEqual(solver.DiscFacEff, 0.9503999999999999) self.assertAlmostEqual(solver.PermShkMinNext, 0.850430160026919) self.assertAlmostEqual(solver.cFuncNowCnst(4).tolist(), 4.0) self.assertAlmostEqual(solver.prepareToCalcEndOfPrdvP()[0], -0.2491750859108316) self.assertAlmostEqual(solver.prepareToCalcEndOfPrdvP()[-1], 19.74982491408914) EndOfPrdvP = solver.calcEndOfPrdvP() self.assertAlmostEqual(EndOfPrdvP[0], 6622.251864311334) self.assertAlmostEqual(EndOfPrdvP[-1], 0.026301061207747087) solution = solver.makeBasicSolution(EndOfPrdvP, solver.aNrmNow, solver.makeLinearcFunc) solver.addMPCandHumanWealth(solution) self.assertAlmostEqual(solution.cFunc(4).tolist(), 1.7391265696400773) def test_simulated_values(self): self.agent.initializeSim() self.agent.simulate() self.assertAlmostEqual(self.agent.MPCnow[1], 0.5711503906043797) self.assertAlmostEqual(self.agent.aLvlNow[1], 0.18438326264597635)
class testIndShockConsumerType(unittest.TestCase): def setUp(self): self.agent = IndShockConsumerType( AgentCount = 2, T_sim = 10 ) self.agent.solve() def test_getShocks(self): self.agent.initializeSim() self.agent.simBirth(np.array([True,False])) self.agent.simOnePeriod() self.agent.simBirth(np.array([False,True])) self.agent.getShocks() self.assertEqual(self.agent.PermShkNow[0], 1.0050166461586711) self.assertEqual(self.agent.PermShkNow[1], 1.0050166461586711) self.assertEqual(self.agent.TranShkNow[0], 1.1176912196531754) def test_ConsIndShockSolverBasic(self): LifecycleExample = IndShockConsumerType( **Params.init_lifecycle) LifecycleExample.cycles = 1 LifecycleExample.solve() solver = ConsIndShockSolverBasic(LifecycleExample.solution[1], LifecycleExample.IncomeDstn[0], LifecycleExample.LivPrb[0], LifecycleExample.DiscFac, LifecycleExample.CRRA, LifecycleExample.Rfree, LifecycleExample.PermGroFac[0], LifecycleExample.BoroCnstArt, LifecycleExample.aXtraGrid, LifecycleExample.vFuncBool, LifecycleExample.CubicBool) solver.prepareToSolve() self.assertAlmostEqual(solver.DiscFacEff, 0.9503999999999999) self.assertAlmostEqual(solver.PermShkMinNext, 0.850430160026919) self.assertAlmostEqual(solver.cFuncNowCnst(4).tolist(), 4.0) self.assertAlmostEqual(solver.prepareToCalcEndOfPrdvP()[0], -0.2491750859108316) self.assertAlmostEqual(solver.prepareToCalcEndOfPrdvP()[-1], 19.74982491408914) EndOfPrdvP = solver.calcEndOfPrdvP() self.assertAlmostEqual(EndOfPrdvP[0], 6622.251864311334) self.assertAlmostEqual(EndOfPrdvP[-1], 0.026301061207747087) solution = solver.makeBasicSolution(EndOfPrdvP, solver.aNrmNow, solver.makeLinearcFunc) solver.addMPCandHumanWealth(solution) self.assertAlmostEqual(solution.cFunc(4).tolist(), 1.7391265696400773) def test_simulated_values(self): self.agent.initializeSim() self.agent.simulate() print(self.agent.aLvlNow) self.assertAlmostEqual(self.agent.MPCnow[1], 0.5535801655448935) self.assertAlmostEqual(self.agent.aLvlNow[1], 0.18832361)