Skip to content

Commit

Permalink
for cyclical models, correct order for input params to correspond to t,
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenthall committed Jul 9, 2021
1 parent 4f2ef4d commit 54083db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions HARK/ConsumptionSaving/ConsIndShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ def sim_death(self):
# Determine who dies
DiePrb_by_t_cycle = 1.0 - np.asarray(self.LivPrb)
DiePrb = DiePrb_by_t_cycle[
self.t_cycle - 1
self.t_cycle - 1 if self.cycles == 1 else self.t_cycle
] # Time has already advanced, so look back one

# In finite-horizon problems the previous line gives newborns the
Expand Down Expand Up @@ -3047,7 +3047,7 @@ def construct_assets_grid(parameters):

# Make a dictionary to specify an infinite consumer with a four period cycle
init_cyclical = copy(init_idiosyncratic_shocks)
init_cyclical['PermGroFac'] = [1.082251, 2.8, 0.3, 1.1]
init_cyclical['PermGroFac'] = [1.1, 1.082251, 2.8, 0.3]
init_cyclical['PermShkStd'] = [0.1, 0.1, 0.1, 0.1]
init_cyclical['TranShkStd'] = [0.1, 0.1, 0.1, 0.1]
init_cyclical['LivPrb'] = 4*[0.98]
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def test_lifecyle(self):
"Rfree": 1.03, # Interest factor on assets
"DiscFac": 0.96, # Intertemporal discount factor
"LivPrb": 4 * [0.98], # Survival probability
"PermGroFac": [1.082251, 2.8, 0.3, 1.1],
"PermGroFac": [1.1, 1.082251, 2.8, 0.3],
# Parameters that specify the income distribution over the lifecycle
"PermShkStd": [0.1, 0.1, 0.1, 0.1],
"PermShkCount": 7, # Number of points in discrete approximation to permanent income shocks
Expand Down
9 changes: 5 additions & 4 deletions HARK/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,12 @@ def solve_one_cycle(agent, solution_last):
# Initialize the solution for this cycle, then iterate on periods
solution_cycle = []
solution_next = solution_last
for t in range(T):

cycles_range = [0] + list(range(T - 1, 0, -1))
for k in (range(T-1, -1, -1) if agent.cycles == 1 else cycles_range):
# Update which single period solver to use (if it depends on time)
if hasattr(agent.solve_one_period, "__getitem__"):
solve_one_period = agent.solve_one_period[T - 1 - t]
solve_one_period = agent.solve_one_period[k]
else:
solve_one_period = agent.solve_one_period

Expand All @@ -1019,8 +1021,7 @@ def solve_one_cycle(agent, solution_last):
# Update time-varying single period inputs
for name in agent.time_vary:
if name in these_args:
# solve_dict[name] = eval('agent.' + name + '[t]')
solve_dict[name] = agent.__dict__[name][T - 1 - t]
solve_dict[name] = agent.__dict__[name][k]
solve_dict["solution_next"] = solution_next

# Make a temporary dictionary for this period
Expand Down

0 comments on commit 54083db

Please sign in to comment.