Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 70 additions & 61 deletions HARK/ConsumptionSaving/ConsAggShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
MarkovProcess,
MeanOneLogNormal,
Uniform,
calc_expectation,
expected,
combine_indep_dstns,
)
from HARK.interpolation import (
Expand Down Expand Up @@ -188,7 +188,6 @@ def solveConsAggShock(
AFunc,
Rfunc,
wFunc,
DeprRte,
):
"""
Solve one period of a consumption-saving problem with idiosyncratic and
Expand Down Expand Up @@ -231,8 +230,6 @@ def solveConsAggShock(
The net interest factor on assets as a function of capital ratio k.
wFunc : function
The wage rate for labor as a function of capital-to-labor ratio k.
DeprRte : float
Capital Depreciation Rate

Returns
-------
Expand Down Expand Up @@ -296,9 +293,7 @@ def vPnextFunc(S, a, M):

# Compute end-of-period marginal value of assets
MaggNow = np.tile(np.reshape(Mgrid, (1, Mcount)), (aCount, 1)) # Tiled Mgrid
EndOfPrdvP = (
DiscFac * LivPrb * calc_expectation(IncShkDstn, vPnextFunc, *(aNrmNow, MaggNow))
)
EndOfPrdvP = DiscFac * LivPrb * expected(vPnextFunc, IncShkDstn, (aNrmNow, MaggNow))

# Calculate optimal consumption from each asset gridpoint and endogenous m_t gridpoint
cNrmNow = EndOfPrdvP ** (-1.0 / CRRA)
Expand Down Expand Up @@ -406,8 +401,6 @@ def solve_ConsAggMarkov(
The net interest factor on assets as a function of capital ratio k.
wFunc : function
The wage rate for labor as a function of capital-to-labor ratio k.
DeprRte : float
Capital Depreciation Rate

Returns
-------
Expand Down Expand Up @@ -765,8 +758,8 @@ def solve_KrusellSmith(
default_aXtraGrid_params = {
"aXtraMin": 0.001, # Minimum end-of-period "assets above minimum" value
"aXtraMax": 20, # Maximum end-of-period "assets above minimum" value
"aXtraNestFac": 3, # Exponential nesting factor for aXtraGrid
"aXtraCount": 24, # Number of points in the grid of "assets above minimum"
"aXtraNestFac": 2, # Exponential nesting factor for aXtraGrid
"aXtraCount": 36, # Number of points in the grid of "assets above minimum"
"aXtraExtra": None, # Additional other values to add in grid (optional)
}

Expand Down Expand Up @@ -836,7 +829,7 @@ class AggShockConsumerType(IndShockConsumerType):
"track_vars": ["aNrm", "cNrm", "mNrm", "pLvl"],
}
time_inv_ = IndShockConsumerType.time_inv_.copy()
time_inv_ += ["Mgrid", "AFunc", "Rfunc", "wFunc", "DeprRte", "PermGroFacAgg"]
time_inv_ += ["Mgrid", "AFunc", "Rfunc", "wFunc", "PermGroFacAgg"]
try:
time_inv_.remove("vFuncBool")
time_inv_.remove("CubicBool")
Expand All @@ -849,7 +842,6 @@ class AggShockConsumerType(IndShockConsumerType):
"AFunc",
"Rfunc",
"wFunc",
"DeprRte",
"PermGroFacAgg",
"AggShkDstn",
]
Expand Down Expand Up @@ -1220,7 +1212,17 @@ def make_assets_grid_KS(aMin, aMax, aCount, aNestFac):


def make_KS_transition_arrays(
aGrid, Mgrid, AFunc, LbrInd, UrateB, UrateG, ProdB, ProdG, MrkvIndArray
aGrid,
Mgrid,
AFunc,
LbrInd,
UrateB,
UrateG,
ProdB,
ProdG,
MrkvIndArray,
CapShare,
DeprRte,
):
"""
Construct the attributes ProbArray, mNextArray, MnextArray, and RnextArray,
Expand Down Expand Up @@ -1248,6 +1250,10 @@ def make_KS_transition_arrays(
TFP in the "good" aggregate state.
MrkvIndArray : np.array
Markov transition probabilities from the perspective of the individual.
CapShare : float
Capital's share of production.
DeprRte : float
Capital depreciation rate.

Returns
-------
Expand Down Expand Up @@ -1651,52 +1657,23 @@ def get_poststates(self):
###############################################################################


CRRA = 2.0
DiscFac = 0.96

# Parameters for a Cobb-Douglas economy
PermGroFacAgg = 1.00 # Aggregate permanent income growth factor
PermShkAggCount = (
3 # Number of points in discrete approximation to aggregate permanent shock dist
)
TranShkAggCount = (
3 # Number of points in discrete approximation to aggregate transitory shock dist
)
PermShkAggStd = 0.0063 # Standard deviation of log aggregate permanent shocks
TranShkAggStd = 0.0031 # Standard deviation of log aggregate transitory shocks
DeprRte = 0.025 # Capital depreciation rate
CapShare = 0.36 # Capital's share of income
DiscFacPF = DiscFac # Discount factor of perfect foresight calibration
CRRAPF = CRRA # Coefficient of relative risk aversion of perfect foresight calibration
intercept_prev = 0.0 # Intercept of aggregate savings function
slope_prev = 1.0 # Slope of aggregate savings function
verbose_cobb_douglas = (
True # Whether to print solution progress to screen while solving
)
T_discard = 200 # Number of simulated "burn in" periods to discard when updating AFunc
# Damping factor when updating AFunc; puts DampingFac weight on old params, rest on new
DampingFac = 0.5
max_loops = 20 # Maximum number of AFunc updating loops to allow


# Make a dictionary to specify a Cobb-Douglas economy
init_cobb_douglas = {
"PermShkAggCount": PermShkAggCount,
"TranShkAggCount": TranShkAggCount,
"PermShkAggStd": PermShkAggStd,
"TranShkAggStd": TranShkAggStd,
"DeprRte": DeprRte,
"CapShare": CapShare,
"DiscFac": DiscFacPF,
"CRRA": CRRAPF,
"PermGroFacAgg": PermGroFacAgg,
"AggregateL": 1.0,
"intercept_prev": intercept_prev,
"slope_prev": slope_prev,
"verbose": verbose_cobb_douglas,
"T_discard": T_discard,
"DampingFac": DampingFac,
"max_loops": max_loops,
"PermShkAggCount": 3, # Number of points in discrete approximation to aggregate permanent shock dist
"TranShkAggCount": 3, # Number of points in discrete approximation to aggregate transitory shock dist
"PermShkAggStd": 0.0063, # Standard deviation of log aggregate permanent shocks
"TranShkAggStd": 0.0031, # Standard deviation of log aggregate transitory shocks
"DeprRte": 0.025, # Capital depreciation rate
"CapShare": 0.36, # Capital's share of income
"DiscFac": 0.96, # Discount factor of perfect foresight calibration
"CRRA": 2.0, # Coefficient of relative risk aversion of perfect foresight calibration
"PermGroFacAgg": 1.0, # Aggregate permanent income growth factor
"intercept_prev": 0.0, # Intercept of aggregate savings function
"slope_prev": 1.0, # Slope of aggregate savings function,
"verbose": False, # Whether to print solution progress to screen while solving
"T_discard": 200, # Number of simulated "burn in" periods to discard when updating AFunc
"DampingFac": 0.1, # Damping factor when updating AFunc
"max_loops": 20, # Maximum number of AFunc updating loops to allow
}


Expand Down Expand Up @@ -2014,6 +1991,22 @@ def calc_AFunc(self, MaggNow, AaggNow):
return AggShocksDynamicRule(AFunc)


# Make a dictionary to specify a small open economy
init_small_open_economy = {
"PermShkAggCount": 3, # Number of points in discrete approximation to aggregate permanent shock dist
"TranShkAggCount": 3, # Number of points in discrete approximation to aggregate transitory shock dist
"PermShkAggStd": 0.0063, # Standard deviation of log aggregate permanent shocks
"TranShkAggStd": 0.0031, # Standard deviation of log aggregate transitory shocks
"Rfree": 1.02, # exogenous and fixed return factor on assets
"wRte": 1.0, # exogenous and fixed wage rate
"PermGroFacAgg": 1.0, # Aggregate permanent income growth factor
"intercept_prev": 0.0, # Intercept of aggregate savings function
"slope_prev": 1.0, # Slope of aggregate savings function,
"verbose": False, # Whether to print solution progress to screen while solving
"max_loops": 1, # Maximum number of AFunc updating loops to allow, should always be 1
}


class SmallOpenEconomy(Market):
"""
A class for representing a small open economy, where the wage rate and interest rate are
Expand All @@ -2034,6 +2027,8 @@ class SmallOpenEconomy(Market):

def __init__(self, agents=None, tolerance=0.0001, act_T=1000, **kwds):
agents = agents if agents is not None else list()
params = init_small_open_economy.copy()
params.update(**kwds)
Market.__init__(
self,
agents=agents,
Expand All @@ -2052,6 +2047,7 @@ def __init__(self, agents=None, tolerance=0.0001, act_T=1000, **kwds):
distributions=["PermShkAggDstn", "TranShkAggDstn", "AggShkDstn"],
tolerance=tolerance,
act_T=act_T,
**params,
)
self.assign_parameters(**kwds)
self.update()
Expand Down Expand Up @@ -2230,8 +2226,8 @@ def get_AggShocks(self):
init_mrkv_cobb_douglas["PermGroFacAgg"] = [0.98, 1.02]
init_mrkv_cobb_douglas["MrkvArray"] = MrkvArray
init_mrkv_cobb_douglas["MrkvInit"] = 0
init_mrkv_cobb_douglas["slope_prev"] = 2 * [slope_prev]
init_mrkv_cobb_douglas["intercept_prev"] = 2 * [intercept_prev]
init_mrkv_cobb_douglas["slope_prev"] = 2 * [1.0]
init_mrkv_cobb_douglas["intercept_prev"] = 2 * [0.0]


class CobbDouglasMarkovEconomy(CobbDouglasEconomy):
Expand Down Expand Up @@ -2623,6 +2619,19 @@ def calc_AFunc(self, MaggNow, AaggNow):
return AggShocksDynamicRule(AFunc_list)


# Make a dictionary to specify a small open Markov economy
init_mrkv_small_open_economy = init_small_open_economy.copy()
init_mrkv_small_open_economy["PermShkAggStd"] = [0.012, 0.006]
init_mrkv_small_open_economy["TranShkAggStd"] = [0.006, 0.003]
init_mrkv_small_open_economy["PermGroFacAgg"] = [0.98, 1.02]
init_mrkv_small_open_economy["MrkvArray"] = MrkvArray
init_mrkv_small_open_economy["MrkvInit"] = 0
init_mrkv_small_open_economy["slope_prev"] = 2 * [1.0]
init_mrkv_small_open_economy["intercept_prev"] = 2 * [0.0]
init_mrkv_small_open_economy["Rfree"] = 1.02
init_mrkv_small_open_economy["wRte"] = 1.0


class SmallOpenMarkovEconomy(CobbDouglasMarkovEconomy, SmallOpenEconomy):
"""
A class for representing a small open economy, where the wage rate and interest rate are
Expand All @@ -2633,7 +2642,7 @@ class SmallOpenMarkovEconomy(CobbDouglasMarkovEconomy, SmallOpenEconomy):

def __init__(self, agents=None, tolerance=0.0001, act_T=1000, **kwds):
agents = agents if agents is not None else list()
temp_dict = init_mrkv_cobb_douglas.copy()
temp_dict = init_mrkv_small_open_economy.copy()
temp_dict.update(kwds)
CobbDouglasMarkovEconomy.__init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion HARK/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,7 @@ def solve_agent(agent, verbose, from_solution=None, from_t=None):
"Finished cycle #"
+ str(completed_cycles)
+ " in "
+ str(t_now - t_last)
+ "{:.6f}".format(t_now - t_last)
+ " seconds, solution distance = "
+ str(solution_distance)
)
Expand Down
Loading
Loading