コード例 #1
0
class testKrusellSmith(unittest.TestCase):
    def setUp(self):
        # Make one agent type and an economy for it to live in
        self.agent = KrusellSmithType()
        self.agent.cycles = 0
        self.agent.AgentCount = 1000  # Low number of simulated agents
        self.economy = KrusellSmithEconomy(agents=[self.agent])
        self.economy.max_loops = 2  # Quit early
        self.economy.act_T = 1100  # Shorter simulated period
        self.economy.discard_periods = 100
        self.economy.verbose = False  # Turn off printed messages

    def test_agent(self):
        self.agent.getEconomyData(self.economy)
        self.agent.solve()
        self.assertAlmostEqual(
            self.agent.solution[0].cFunc[0](10., self.economy.MSS), 1.23867751)

    def test_economy(self):
        self.agent.getEconomyData(self.economy)
        self.economy.makeMrkvHist(
        )  # Make a simulated history of aggregate shocks
        self.economy.solve(
        )  # Solve for the general equilibrium of the economy

        self.economy.AFunc = self.economy.dynamics.AFunc
        self.assertAlmostEqual(self.economy.AFunc[0].slope, 1.0014463644834282)

        self.assertAlmostEqual(self.economy.history['Aprev'][4],
                               11.009107526443584)

        self.assertAlmostEqual(self.economy.history['MrkvNow'][40], 1)

        self.assertAlmostEqual(self.economy.history['Urate'][12],
                               0.040000000000000036)
コード例 #2
0
ファイル: KrusellSmith.py プロジェクト: econ-ark/KrusellSmith
# %% [markdown]
# ## New and Improved Krusell-Smith Model
#
# The figures above were generated from a model that is very similar to, but not exactly like, the model presented in Krusell & Smith (1998), using tools that were already in HARK and could be adapted for this purpose.  This model lacks serially correlated employment states for individual agents, but is otherwise identical to the KS model.
#
# More recently, we have added a model to HARK that exactly replicates the Krusell-Smith model (without dynastic discount factor heterogeneity).  In the cells below, we present a basic example of using this model. The default parameters are taken directly from Krusell & Smith (1998) and their results are replicated almost exactly.

# %%
# Import Krusell-Smith model
from HARK.ConsumptionSaving.ConsAggShockModel import KrusellSmithType, KrusellSmithEconomy
from time import time
from scipy.stats import linregress

# %%
# Make default KS agent type and economy
KSeconomy = KrusellSmithEconomy()
KSeconomy.verbose = False
KStype = KrusellSmithType()
KStype.cycles = 0
KStype.getEconomyData(KSeconomy)
KSeconomy.agents = [KStype]
KSeconomy.makeMrkvHist()

# %%
# Solve the Krusell-Smith economy
t0 = time()
print("Now solving for the equilibrium of the Krusell-Smith (1998) model.  This might take a few minutes...")
KSeconomy.solve()
t1 = time()
print('Solving the Krusell-Smith model took ' + str(t1-t0) + ' seconds.')