class testIndShockExplicitPermIncConsumerType(unittest.TestCase):
    def setUp(self):
        self.agent = IndShockExplicitPermIncConsumerType(cycles=1, **GenIncDictionary)
        self.agent.solve()

    def test_solution(self):
        pLvlGrid = self.agent.pLvlGrid[0]
        self.assertAlmostEqual(self.agent.pLvlGrid[0][0], 1.0)

        self.assertAlmostEqual(self.agent.solution[0].mLvlMin(pLvlGrid[0]), 0.0)

        self.assertAlmostEqual(
            self.agent.solution[0].cFunc(10, pLvlGrid[5]).tolist(), 5.6030075768585075
        )
class testIndShockExplicitPermIncConsumerType(unittest.TestCase):
    def setUp(self):
        self.agent = IndShockExplicitPermIncConsumerType(**GenIncDictionary)
        self.agent.solve()

    def test_solution(self):
        pLvlGrid = self.agent.pLvlGrid[0]
        self.assertAlmostEqual(self.agent.pLvlGrid[0][0], 0.009010968834256606)

        self.assertAlmostEqual(self.agent.solution[0].mLvlMin(pLvlGrid[0]),
                               0.0)

        self.assertAlmostEqual(
            self.agent.solution[0].cFunc(10, pLvlGrid[5]).tolist(),
            0.787450633872639)
 def setUp(self):
     self.agent = IndShockExplicitPermIncConsumerType(cycles=1,
                                                      **GenIncDictionary)
     self.agent.solve()
Beispiel #4
0
    0,
    "pLvlPctiles":
    np.concatenate(([0.001, 0.005, 0.01,
                     0.03], np.linspace(0.05, 0.95,
                                        num=19), [0.97, 0.99, 0.995, 0.999])),
    "PermGroFac": [
        1.0
    ],  # Permanent income growth factor - long run permanent income growth doesn't work yet    
}

# %% [markdown]
# Let's now create an instance of the type of consumer we are interested in and solve this agent's problem with an infinite horizon (cycles=0).

# %%
# Make and solve an example "explicit permanent income" consumer with idiosyncratic shocks
ExplicitExample = IndShockExplicitPermIncConsumerType(**GenIncDictionary)

print('Here, the lowest percentile is ' +
      str(GenIncDictionary['pLvlPctiles'][0] * 100))
print('and the highest percentile is ' +
      str(GenIncDictionary['pLvlPctiles'][-1] * 100) + '.\n')

ExplicitExample.solve()

# %% [markdown]
# In the cell below, we generate a plot of the consumption function for explicit permanent income consumer at different income levels.

# %% {"code_folding": []}
# Plot the consumption function at various permanent income levels.
print('Consumption function by pLvl for explicit permanent income consumer:')
pLvlGrid = ExplicitExample.pLvlGrid[0]
Beispiel #5
0
    "based on percentiles of the long run distribution of pLvl for the given parameters. These percentiles"
)
print(
    "are specified in the attribute pLvlPctiles. Here, the lowest percentile is "
    + str(init_explicit_perm_inc["pLvlPctiles"][0] * 100)
    + " and the highest"
)
print(
    "percentile is "
    + str(init_explicit_perm_inc["pLvlPctiles"][-1] * 100)
    + ".\n"
)

# %%
# Make and solve an example "explicit permanent income" consumer with idiosyncratic shocks
ExplicitExample = IndShockExplicitPermIncConsumerType()
t_start = process_time()
ExplicitExample.solve()
t_end = process_time()
print(
    "Solving an explicit permanent income consumer took "
    + mystr(t_end - t_start)
    + " seconds."
)

# %%
# Plot the consumption function at various permanent income levels
print("Consumption function by pLvl for explicit permanent income consumer:")
pLvlGrid = ExplicitExample.pLvlGrid[0]
mLvlGrid = np.linspace(0, 20, 300)
for p in pLvlGrid: