コード例 #1
0
class testPersistentShockConsumerType(unittest.TestCase):
    def setUp(self):
        # "persistent idiosyncratic shocks" model
        PrstIncCorr = 0.98  # Serial correlation coefficient for persistent income
        persistent_shocks = copy(GenIncDictionary)
        persistent_shocks["PrstIncCorr"] = PrstIncCorr

        # "persistent idisyncratic shocks" consumer
        self.agent = PersistentShockConsumerType(cycles=1, **persistent_shocks)
        self.agent.solve()

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

        self.assertAlmostEqual(
            self.agent.solution[0].cFunc(10, pLvlGrid[1]).tolist(),
            5.6030075768585075)

    def test_simulation(self):
        self.agent.T_sim = 25

        # why does ,"bLvlNow" not work here?
        self.agent.track_vars = ["aLvl", "mLvl", "cLvl", "pLvl"]
        self.agent.initialize_sim()
        self.agent.simulate()

        self.assertAlmostEqual(np.mean(self.agent.history["mLvl"]),
                               1.2043946738813716)
コード例 #2
0
plt.ylabel('Consumption level cLvl')
plt.show()

# %%
# Plot the value function at various persistent income levels
if PersistentExample.vFuncBool:
    pGrid = PersistentExample.pLvlGrid[0]
    M = np.linspace(0.001, 5, 300)
    for p in pGrid:
        M_temp = M + PersistentExample.solution[0].mLvlMin(p)
        C = PersistentExample.solution[0].vFunc(M_temp,
                                                p * np.ones_like(M_temp))
        plt.plot(M_temp, C)
    plt.ylim([-200, 0])
    plt.xlabel('Market resource level mLvl')
    plt.ylabel('Value v')
    plt.show()

# %%
# Simulate some data
PersistentExample.T_sim = 500
PersistentExample.track_vars = ['mLvl', 'cLvl', 'pLvl']
PersistentExample.initialize_sim()
PersistentExample.simulate()
plt.plot(np.mean(PersistentExample.history['mLvl'], axis=1))
plt.xlabel('Simulated time period')
plt.ylabel('Average market resources mLvl')
plt.show()

# %%