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 += ["mLvl"]
        self.tct.initialize_sim()
        self.tct.simulate()

        self.assertAlmostEqual(self.tct.history["mLvl"][15][0], 5.820630251772332)
Exemplo n.º 2
0
    def setUp(self):
        # Set up and solve TBS
        base_primitives = {
            "UnempPrb": 0.015,
            "DiscFac": 0.9,
            "Rfree": 1.1,
            "PermGroFac": 1.05,
            "CRRA": 0.95,
        }
        TBSType = TractableConsumerType(**base_primitives)
        TBSType.solve()

        # Set up and solve Markov
        MrkvArray = [
            np.array([
                [
                    1.0 - base_primitives["UnempPrb"],
                    base_primitives["UnempPrb"]
                ],
                [0.0, 1.0],
            ])
        ]
        Markov_primitives = {
            "CRRA":
            base_primitives["CRRA"],
            "Rfree":
            np.array(2 * [base_primitives["Rfree"]]),
            "PermGroFac": [
                np.array(2 * [
                    base_primitives["PermGroFac"] /
                    (1.0 - base_primitives["UnempPrb"])
                ])
            ],
            "BoroCnstArt":
            None,
            "PermShkStd": [0.0],
            "PermShkCount":
            1,
            "TranShkStd": [0.0],
            "TranShkCount":
            1,
            "T_total":
            1,
            "UnempPrb":
            0.0,
            "UnempPrbRet":
            0.0,
            "T_retire":
            0,
            "IncUnemp":
            0.0,
            "IncUnempRet":
            0.0,
            "aXtraMin":
            0.001,
            "aXtraMax":
            TBSType.mUpperBnd,
            "aXtraCount":
            48,
            "aXtraExtra": [None],
            "aXtraNestFac":
            3,
            "LivPrb": [
                np.array([1.0, 1.0]),
            ],
            "DiscFac":
            base_primitives["DiscFac"],
            "Nagents":
            1,
            "psi_seed":
            0,
            "xi_seed":
            0,
            "unemp_seed":
            0,
            "tax_rate":
            0.0,
            "vFuncBool":
            False,
            "CubicBool":
            True,
            "MrkvArray":
            MrkvArray,
            "T_cycle":
            1,
        }

        MarkovType = MarkovConsumerType(**Markov_primitives)
        MarkovType.cycles = 0
        employed_income_dist = DiscreteDistribution(np.ones(1),
                                                    np.array([[1.0], [1.0]]))
        unemployed_income_dist = DiscreteDistribution(np.ones(1),
                                                      np.array([[1.0], [0.0]]))
        MarkovType.IncShkDstn = [[
            employed_income_dist, unemployed_income_dist
        ]]

        MarkovType.solve()
        MarkovType.unpack("cFunc")

        self.TBSType = TBSType
        self.MarkovType = MarkovType
Exemplo n.º 3
0
# \begin{align}
# \check{m} & = 1 + \left(\frac{1}{(\gamma-r)+(1+(\gamma/\mho)(1-(\gamma/\mho)(\rho-1)/2))}\right)
# \end{align}
#

# %% {"code_folding": [0]}
# Define a parameter dictionary and representation of the agents for the tractable buffer stock model
TBS_dictionary = {
    'UnempPrb':
    .00625,  # Prob of becoming unemployed; working life of 1/UnempProb = 160 qtrs
    'DiscFac': 0.975,  # Intertemporal discount factor
    'Rfree': 1.01,  # Risk-free interest factor on assets
    'PermGroFac': 1.0025,  # Permanent income growth factor (uncompensated)
    'CRRA': 2.5
}  # Coefficient of relative risk aversion
MyTBStype = TractableConsumerType(**TBS_dictionary)

# %% [markdown]
# ## Target Wealth
#
# Whether the model exhibits a "target" or "stable" level of the wealth-to-permanent-income ratio for employed consumers depends on whether the 'Growth Impatience Condition' (the GIC) holds:
#
# \begin{align}\label{eq:GIC}
#  \left(\frac{(R \beta (1-\mho))^{1/\rho}}{\Gamma}\right)  & <  1
# \\ \left(\frac{(R \beta (1-\mho))^{1/\rho}}{G (1-\mho)}\right)  &<  1
# \\ \left(\frac{(R \beta)^{1/\rho}}{G} (1-\mho)^{-\rho}\right)  &<  1
# \end{align}
# and recall (from [PerfForesightCRRA](http://econ.jhu.edu/people/ccarroll/public/lecturenotes/consumption/PerfForesightCRRA/)) that the perfect foresight 'Growth Impatience Factor' is
# \begin{align}\label{eq:PFGIC}
# \left(\frac{(R \beta)^{1/\rho}}{G}\right)  &<  1
# \end{align}
Exemplo n.º 4
0
    def setUp(self):
        # Set up and solve TBS
        base_primitives = {'UnempPrb': .015,
                           'DiscFac': 0.9,
                           'Rfree': 1.1,
                           'PermGroFac': 1.05,
                           'CRRA': .95}
        TBSType = TractableConsumerType(**base_primitives)
        TBSType.solve()

        # Set up and solve Markov
        MrkvArray = [np.array([[1.0-base_primitives['UnempPrb'], base_primitives['UnempPrb']],[0.0, 1.0]])]
        Markov_primitives = {"CRRA": base_primitives['CRRA'],
                             "Rfree": np.array(2*[base_primitives['Rfree']]),
                             "PermGroFac": [np.array(2*[base_primitives['PermGroFac'] /
                                            (1.0-base_primitives['UnempPrb'])])],
                             "BoroCnstArt": None,
                             "PermShkStd": [0.0],
                             "PermShkCount": 1,
                             "TranShkStd": [0.0],
                             "TranShkCount": 1,
                             "T_total": 1,
                             "UnempPrb": 0.0,
                             "UnempPrbRet": 0.0,
                             "T_retire": 0,
                             "IncUnemp": 0.0,
                             "IncUnempRet": 0.0,
                             "aXtraMin": 0.001,
                             "aXtraMax": TBSType.mUpperBnd,
                             "aXtraCount": 48,
                             "aXtraExtra": [None],
                             "aXtraNestFac": 3,
                             "LivPrb":[np.array([1.0,1.0]),],
                             "DiscFac": base_primitives['DiscFac'],
                             'Nagents': 1,
                             'psi_seed': 0,
                             'xi_seed': 0,
                             'unemp_seed': 0,
                             'tax_rate': 0.0,
                             'vFuncBool': False,
                             'CubicBool': True,
                             'MrkvArray': MrkvArray,
                             'T_cycle':1
                             }

        MarkovType = MarkovConsumerType(**Markov_primitives)
        MarkovType.cycles = 0
        employed_income_dist = DiscreteDistribution(np.ones(1),
                                                    [np.ones(1),
                                                     np.ones(1)])
        unemployed_income_dist = DiscreteDistribution(np.ones(1),
                                                      [np.ones(1),
                                                       np.zeros(1)])
        MarkovType.IncomeDstn = [[employed_income_dist,
                                  unemployed_income_dist]]

        MarkovType.solve()
        MarkovType.unpackcFunc()

        self.TBSType = TBSType
        self.MarkovType = MarkovType
 def setUp(self):
     # Create portfolio choice consumer type
     self.tct = TractableConsumerType()
     # Solve the model under the given parameters
     self.tct.solve()
    "CRRA": 1.0,
}  # Coefficient of relative risk aversion

# %%
# Define a dictionary to be used in case of simulation
simulation_values = {
    "aLvlInitMean": 0.0,  # Mean of log initial assets for new agents
    "aLvlInitStd": 1.0,  # Stdev of log initial assets for new agents
    "AgentCount": 10000,  # Number of agents to simulate
    "T_sim": 120,  # Number of periods to simulate
    "T_cycle": 1,
}  # Number of periods in the cycle

# %%
# Make and solve a tractable consumer type
ExampleType = TractableConsumerType(**base_primitives)
t_start = process_time()
ExampleType.solve()
t_end = process_time()
print("Solving a tractable consumption-savings model took " +
      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)

# %%
Exemplo n.º 7
0
        InfiniteType.a_init = 0 * np.ones_like(a_init)

        # Make histories of permanent income levels for the infinite horizon type
        p_init_base = np.ones(Params.sim_pop_size, dtype=float)
        InfiniteType.p_init = p_init_base

        # Use a "tractable consumer" instead if desired.
        # If you want this to work, you must edit TractableBufferStockModel slightly.
        # See comments around line 34 in that module for instructions.
        if Params.do_tractable:
            from HARK.ConsumptionSaving.TractableBufferStockModel import TractableConsumerType
            TractableInfType = TractableConsumerType(
                DiscFac=0.99,  # will be overwritten
                UnempPrb=1 - InfiniteType.LivPrb[0],
                Rfree=InfiniteType.Rfree,
                PermGroFac=InfiniteType.PermGroFac[0],
                CRRA=InfiniteType.CRRA,
                sim_periods=InfiniteType.sim_periods,
                IncUnemp=InfiniteType.IncUnemp,
                Nagents=InfiniteType.Nagents)
            TractableInfType.p_init = InfiniteType.p_init
            TractableInfType.timeFwd()
            TractableInfType.TranShkHist = InfiniteType.TranShkHist
            TractableInfType.PermShkHist = InfiniteType.PermShkHist
            TractableInfType.a_init = InfiniteType.a_init

        # Set the type list for the infinite horizon estimation
        if Params.do_tractable:
            short_type_list = [TractableInfType]
            spec_add = 'TC'
        else:
Exemplo n.º 8
0
        R, mE):  # Function that gives us locus of where change in mE is zero
    cE = (1 - R**(-1)) * mE + R**(-1)
    return cE


def cEDelEqZero(
        R, k, Pi,
        mE):  # Function that gives us locus of where change in cE is zero
    cE = (R * k * mE * Pi) / (1 + R * k * Pi)
    return cE


# %% {"code_folding": []}
# Define and solve the model

MyTBStype = TractableConsumerType(**TBS_dictionary)
MyTBStype.solve()

UnempPrb = MyTBStype.UnempPrb
DiscFac = MyTBStype.DiscFac
R = MyTBStype.Rfree
PermGroFacCmp = MyTBStype.PermGroFacCmp
k = MyTBStype.PFMPC
CRRA = MyTBStype.CRRA
Rnrm = MyTBStype.Rnrm
Pi = PiFunc(R, DiscFac, CRRA, UnempPrb, PermGroFacCmp)

# Define the range of mE to plot over
mE_range = np.linspace(0, 8, 1000)
cE = MyTBStype.solution[0].cFunc(mE_range)