dcegm.final_periods

Wrapper to solve the final period of the model.

Functions

solve_last_two_periods(params, continuous_states_info, ...)

Solves the last two periods of the model.

solve_final_period(→ Tuple[jax.numpy.ndarray, ...)

Compute solution to final period for policy and value function.

solve_final_period_discrete(...)

Solve final period for only discrete states.

solve_final_period_second_continuous(...)

Solve final period with second continuous state.

calc_value_and_marg_util_for_each_gridpoint(...)

Continuous state is missing here!

calc_value_and_marg_util_for_each_gridpoint_second_continuous(...)

Continuous state is missing here!

calc_value_and_budget_for_each_gridpoint(...)

calc_value_for_each_gridpoint_second_continuous(...)

Module Contents

dcegm.final_periods.solve_last_two_periods(params: Dict[str, float], continuous_states_info: Dict[str, Any], cont_grids_next_period: Dict[str, jax.numpy.ndarray], income_shock_weights: jax.numpy.ndarray, model_funcs: Dict[str, Callable], last_two_period_batch_info, value_solved, policy_solved, endog_grid_solved, debug_info)

Solves the last two periods of the model.

The last two periods are solved using the EGM algorithm. The last period is solved using the user-specified utility function and the second to last period is solved using the user-specified utility function and the user-specified bequest function.

Parameters:
  • wealth_beginning_of_period (np.ndarray) – 2d array of shape (n_states, n_grid_wealth) of the wealth at the beginning of the period.

  • params (dict) – Dictionary of model parameters.

  • compute_utility (callable) – User supplied utility function.

  • compute_marginal_utility (callable) – User supplied marginal utility function.

  • last_two_period_batch_info (dict) – Dictionary containing information about the batch size and the state space.

  • value_solved (np.ndarray) – 3d array of shape (n_states, n_grid_wealth, n_income_shocks) of the value function for all states, end of period assets, and income shocks.

  • endog_grid_solved (np.ndarray) – 3d array of shape (n_states, n_grid_wealth, n_income_shocks) of the endogenous grid for all states, end of period assets, and income shocks.

dcegm.final_periods.solve_final_period(idx_state_choices_final_period, idx_parent_states_final_period, state_choice_mat_final_period, continuous_states_info: Dict[str, Any], cont_grids_next_period: Dict[str, jax.numpy.ndarray], params: Dict[str, float], model_funcs: Dict[str, Callable], value_solved, policy_solved, endog_grid_solved) Tuple[jax.numpy.ndarray, jax.numpy.ndarray, jax.numpy.ndarray, jax.numpy.ndarray, jax.numpy.ndarray]

Compute solution to final period for policy and value function.

In the last period, everything is consumed, i.e. consumption = savings. Args:

Returns:

  • marginal_utilities_choices (np.ndarray): 3d array of shape

    (n_states, n_grid_wealth, n_income_shocks) of the marginal utility of consumption for all final states, end of period assets, and income shocks.

  • final_value (np.ndarray): 3d array of shape

    (n_states, n_grid_wealth, n_income_shocks) of the optimal value function for all final states, end of period assets, and income shocks.

  • final_policy (np.ndarray): 3d array of shape

    (n_states, n_grid_wealth, n_income_shocks) of the optimal policy for all final states, end of period assets, and income shocks.

Return type:

tuple

dcegm.final_periods.solve_final_period_discrete(idx_state_choices_final_period, idx_parent_states_final_period, state_choice_mat_final_period, cont_grids_next_period: Dict[str, jax.numpy.ndarray], params: Dict[str, float], compute_utility: Callable, compute_marginal_utility: Callable, value_solved, policy_solved, endog_grid_solved)

Solve final period for only discrete states.

Here we make use a trick to solve the final period directly at the wealth gridpoints of next period. When saving the solution, we take (randomly) the middle of income shock draws.

dcegm.final_periods.solve_final_period_second_continuous(idx_state_choices_final_period, idx_parent_states_final_period, state_choice_mat_final_period, cont_grids_next_period: Dict[str, jax.numpy.ndarray], continuous_states_info: Dict[str, Any], params: Dict[str, float], model_funcs: Dict[str, Callable], value_solved, policy_solved, endog_grid_solved)

Solve final period with second continuous state.

Here we solve the final period two times: Once for wealth and second continuous calculated by the law of motion and once for their exogenous grid values. We do that, because the solution is always assumed to be calculated on the exogenous grid of the second continuous state.

dcegm.final_periods.calc_value_and_marg_util_for_each_gridpoint(state_choice_vec, wealth, params, compute_utility, compute_marginal_utility)

Continuous state is missing here!

dcegm.final_periods.calc_value_and_marg_util_for_each_gridpoint_second_continuous(state_choice_vec, wealth_final_period, second_continuous_state, params, compute_utility, compute_marginal_utility)

Continuous state is missing here!

dcegm.final_periods.calc_value_and_budget_for_each_gridpoint(state_choice_vec, asset_grid_point_end_of_previous_period, second_continuous_state, params, compute_utility, compute_assets_begin_of_period)
dcegm.final_periods.calc_value_for_each_gridpoint_second_continuous(state_choice_vec, wealth_final_period, second_continuous_state, params, compute_utility)