Ejemplo n.º 1
0
    def test_ConsIndShockSolverBasic(self):
        LifecycleExample = IndShockConsumerType(**init_lifecycle)
        LifecycleExample.cycles = 1
        LifecycleExample.solve()

        solver = ConsIndShockSolverBasic(
            LifecycleExample.solution[1], LifecycleExample.IncomeDstn[0],
            LifecycleExample.LivPrb[0], LifecycleExample.DiscFac,
            LifecycleExample.CRRA, LifecycleExample.Rfree,
            LifecycleExample.PermGroFac[0], LifecycleExample.BoroCnstArt,
            LifecycleExample.aXtraGrid, LifecycleExample.vFuncBool,
            LifecycleExample.CubicBool)

        solver.prepareToSolve()

        self.assertAlmostEqual(solver.DiscFacEff, 0.9503999999999999)
        self.assertAlmostEqual(solver.PermShkMinNext, 0.850430160026919)
        self.assertAlmostEqual(solver.cFuncNowCnst(4).tolist(), 4.0)
        self.assertAlmostEqual(solver.prepareToCalcEndOfPrdvP()[0],
                               -0.2491750859108316)
        self.assertAlmostEqual(solver.prepareToCalcEndOfPrdvP()[-1],
                               19.74982491408914)

        EndOfPrdvP = solver.calcEndOfPrdvP()

        self.assertAlmostEqual(EndOfPrdvP[0], 6622.251864311334)
        self.assertAlmostEqual(EndOfPrdvP[-1], 0.026301061207747087)

        solution = solver.makeBasicSolution(EndOfPrdvP, solver.aNrmNow,
                                            solver.makeLinearcFunc)
        solver.addMPCandHumanWealth(solution)

        self.assertAlmostEqual(solution.cFunc(4).tolist(), 1.7391265696400773)
Ejemplo n.º 2
0
# %%
from HARK.ConsumptionSaving.ConsIndShockModel import ConsIndShockSolverBasic
solver = ConsIndShockSolverBasic(LifecycleExample.solution[1],
                                 LifecycleExample.IncomeDstn[0],
                                 LifecycleExample.LivPrb[0],
                                 LifecycleExample.DiscFac,
                                 LifecycleExample.CRRA,
                                 LifecycleExample.Rfree,
                                 LifecycleExample.PermGroFac[0],
                                 LifecycleExample.BoroCnstArt,
                                 LifecycleExample.aXtraGrid,
                                 LifecycleExample.vFuncBool,
                                 LifecycleExample.CubicBool)

# %%
solver.prepareToSolve()

# %% [markdown]
# Many important values are now calculated and stored in solver, such as the effective discount factor, the smallest permanent income shock, and more.

# %%
solver.DiscFacEff

# %%
solver.PermShkMinNext

# %% [markdown]
# These values were calculated in `setAndUpdateValues`. In `defBoroCnst` that was also called, several things were calculated, for example the consumption function defined by the borrowing constraint.

# %%
plotFuncs([solver.cFuncNowCnst],solver.mNrmMinNow,10)