예제 #1
0
class testIndShockConsumerTypeFast(unittest.TestCase):
    def setUp(self):
        self.agent = IndShockConsumerTypeFast(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 = IndShockConsumerTypeFast(**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)

    def test_simulated_values(self):
        self.agent.initializeSim()
        self.agent.simulate()
        self.assertAlmostEqual(self.agent.MPCnow[1], 0.5711503906043797)

        self.assertAlmostEqual(self.agent.state_now['aLvlNow'][1],
                               0.18438326264597635)
예제 #2
0
    def test_infinite_horizon(self):
        IndShockExample = IndShockConsumerTypeFast(**IdiosyncDict)
        IndShockExample.cycles = 0  # Make this type have an infinite horizon
        IndShockExample.solve()

        self.assertAlmostEqual(IndShockExample.solution[0].mNrmSS, 1.5488165705077026)
        self.assertAlmostEqual(
            IndShockExample.solution[0].cFunc.functions[0].x_list[0], -0.25017509
        )

        IndShockExample.track_vars = ["aNrmNow", "mNrmNow", "cNrmNow", "pLvlNow"]
        IndShockExample.initializeSim()
        IndShockExample.simulate()

        self.assertAlmostEqual(
            IndShockExample.history["mNrmNow"][0][0], 1.0170176090252379
        )