class testTractableBufferStock(unittest.TestCase):
    def setUp(self):
        # Create portfolio choice consumer type
        self.tct = TractableConsumerType()
        # Solve the model under the given parameters
        self.tct.solve()

    def test_simulation(self):

        self.tct.T_sim = 30  # Number of periods to simulate
        self.tct.AgentCount = 10  # Number of agents to simulate
        self.tct.aLvlInitMean = 0.0  # Mean of log initial assets for new agents
        self.tct.aLvlInitStd = 1.0  # stdev of log initial assets for new agents
        self.tct.T_cycle = 1
        self.tct.track_vars += ["mLvlNow"]
        self.tct.initializeSim()
        self.tct.simulate()

        self.assertAlmostEqual(self.tct.history["mLvlNow"][15][0],
                               5.820630251772332)
      str(t_end - t_start) + " seconds.")

# %%
# Plot the consumption function and whatnot
m_upper = 1.5 * ExampleType.mTarg
conFunc_PF = lambda m: ExampleType.h * ExampleType.PFMPC + ExampleType.PFMPC * m
# plotFuncs([ExampleType.solution[0].cFunc,ExampleType.mSSfunc,ExampleType.cSSfunc],0,m_upper)
plotFuncs([ExampleType.solution[0].cFunc, ExampleType.solution[0].cFunc_U], 0,
          m_upper)

# %%
if do_simulation:
    ExampleType(**simulation_values)  # Set attributes needed for simulation
    ExampleType.track_vars = ["mLvlNow"]
    ExampleType.makeShockHistory()
    ExampleType.initializeSim()
    ExampleType.simulate()

# %%
# Now solve the same model using backward induction rather than the analytic method of TBS.
# The TBS model is equivalent to a Markov model with two states, one of them absorbing (permanent unemployment).
MrkvArray = np.array(
    [[1.0 - base_primitives["UnempPrb"], base_primitives["UnempPrb"]],
     [0.0, 1.0]])  # Define the two state, absorbing unemployment Markov array
init_consumer_objects = {
    "CRRA":
    base_primitives["CRRA"],
    "Rfree":
    np.array(
        2 *
        [base_primitives["Rfree"]]),  # Interest factor (same in both states)
示例#3
0
    plt.savefig(
        os.path.join(Figures_HARK_dir, 'PhaseDiagramDecreaseThetaPlot.svg'))
if not in_ipynb:
    plt.show(block=False)
else:
    plt.show(block=True)

# %% [markdown]
# ### Figure 7: Path of $c^{e}$ Before and After $\theta$ Decline

# %%
MyTBStype.T_sim = 100
MyTBStype.aLvlInitMean = 1.
MyTBStype.aLvlInitStd = 0.
MyTBStype.track_vars = ['mLvlNow', 'cLvlNow']
MyTBStype.initializeSim()
MyTBStype.simulate()

# Capture steady states
sscE = MyTBStype.cLvlNow
ssmE = MyTBStype.mLvlNow

# Now lets change the discount factor from 0.96 to 0.97
#MyTBStype.DiscFac = MyTBStype_3.DiscFac
MyTBStype_3.solve()  #remember to resolve the consumer's problem
MyTBStype_3.T_sim = 110
MyTBStype_3.aLvlInitMean = 1.
MyTBStype_3.aLvlInitStd = 0.
MyTBStype_3.track_vars = ['mLvlNow', 'cLvlNow']
MyTBStype_3.initializeSim()
MyTBStype_3.simulate()