コード例 #1
0
    def test_Harmenberg_mtd(self):

        example = IndShockConsumerType(**dict_harmenberg, verbose=0)
        example.cycles = 0
        example.track_vars = ['aNrm', 'mNrm', 'cNrm', 'pLvl', 'aLvl']
        example.T_sim = 20000

        example.solve()

        example.neutral_measure = True
        example.update_income_process()

        example.initialize_sim()
        example.simulate()

        Asset_list = []
        Consumption_list = []
        M_list = []

        for i in range(example.T_sim):
            Assetagg = np.mean(example.history['aNrm'][i])
            Asset_list.append(Assetagg)
            ConsAgg = np.mean(example.history['cNrm'][i])
            Consumption_list.append(ConsAgg)
            Magg = np.mean(example.history['mNrm'][i])
            M_list.append(Magg)

        #########################################################

        example2 = IndShockConsumerType(**dict_harmenberg, verbose=0)
        example2.cycles = 0
        example2.track_vars = ['aNrm', 'mNrm', 'cNrm', 'pLvl', 'aLvl']
        example2.T_sim = 20000

        example2.solve()
        example2.initialize_sim()
        example2.simulate()

        Asset_list2 = []
        Consumption_list2 = []
        M_list2 = []

        for i in range(example2.T_sim):
            Assetagg = np.mean(example2.history['aLvl'][i])
            Asset_list2.append(Assetagg)
            ConsAgg = np.mean(example2.history['cNrm'][i] *
                              example2.history['pLvl'][i])
            Consumption_list2.append(ConsAgg)
            Magg = np.mean(example2.history['mNrm'][i] *
                           example2.history['pLvl'][i])
            M_list2.append(Magg)

        c_std2 = np.std(Consumption_list2)
        c_std1 = np.std(Consumption_list)
        c_std_ratio = c_std2 / c_std1

        self.assertAlmostEqual(c_std2, 0.03768819564871894)
        self.assertAlmostEqual(c_std1, 0.004411745897568616)
        self.assertAlmostEqual(c_std_ratio, 8.542694099741672)
コード例 #2
0
)

# %%
# Compare the value functions for the two types
if IndShockExample.vFuncBool:
    print("Value functions for perfect foresight vs idiosyncratic shocks:")
    plotFuncs(
        [PFexample.solution[0].vFunc, IndShockExample.solution[0].vFunc],
        IndShockExample.solution[0].mNrmMin + 0.5,
        10,
    )

# %%
# Simulate some data; results stored in mNrmNow_hist, cNrmNow_hist, and pLvlNow_hist
if do_simulation:
    IndShockExample.T_sim = 120
    IndShockExample.track_vars = ["mNrmNow", "cNrmNow", "pLvlNow"]
    IndShockExample.makeShockHistory(
    )  # This is optional, simulation will draw shocks on the fly if it isn't run.
    IndShockExample.initializeSim()
    IndShockExample.simulate()

# %%
# Make and solve an idiosyncratic shocks consumer with a finite lifecycle
LifecycleExample = IndShockConsumerType(**init_lifecycle)
LifecycleExample.cycles = (
    1)  # Make this consumer live a sequence of periods exactly once

# %%
start_time = time()
LifecycleExample.solve()
コード例 #3
0
        'mean_lvl': mean_lvl,
        'vars_lvl': vars_lvl,
        'dist_last': sims[-1, ]
    }


# %% [markdown]
# We now configure and solve a buffer-stock agent with a default parametrization.

# %% Create and simulate agent tags=[]
# Create and solve agent

popn = IndShockConsumerType(**init_idiosyncratic_shocks)

# Modify default parameters
popn.T_sim = max(sample_periods_lvl) + 1
popn.AgentCount = max_agents
popn.track_vars = ['mNrm', 'cNrm', 'pLvl']
popn.LivPrb = [1.0]
popn.cycles = 0

# Solve (but do not yet simulate)
popn.solve()

# %% [markdown]
# Under the basic simulation strategy, we have to de-normalize market resources and consumption multiplying them by permanent income. Only then we construct our statistics of interest.
#
# Note that our time-sampling strategy requires that, after enough time has passed, the economy settles on a stable distribution of its agents across states. How can we know this will be the case? [Szeidl (2013)](http://www.personal.ceu.hu/staff/Adam_Szeidl/papers/invariant.pdf) and [Harmenberg (2021)](https://www.sciencedirect.com/science/article/pii/S0165188921001202?via%3Dihub) provide conditions that can give us some reassurance.$\newcommand{\Rfree}{\mathsf{R}}$
#
# 1. [Szeidl (2013)](http://www.personal.ceu.hu/staff/Adam_Szeidl/papers/invariant.pdf) shows that if $$\log \left[\frac{(\Rfree\beta)^{1/\rho}}{\PermGroFac}
# \right] < \Ex[\log \PermShk],$$ then there is a stable invariant distribution of normalized market resources $\mNrm$.