def retirementChoiceSolver(solution_tp1,income_distrib,p_zero_income,survival_prob,beta,rho,R,Gamma,constrained,a_grid,calc_vFunc,cubic_splines,solution_retired): ''' Solves one period of an infinite horizon retirement choice problem. ''' # Solve the period when we're working solution_working = consumptionSavingSolverENDG(solution_tp1,income_distrib,p_zero_income,survival_prob,beta,rho,R,Gamma,constrained,a_grid,calc_vFunc,cubic_splines) # Determine which choice is best at "infinity" large_m = 1000.0*np.max(a_grid) v_check = np.asarray([solution_working.vFunc(large_m),solution_retired.vFunc(large_m)]) v_best = np.argmax(v_check) # Construct and return the solution for this period vFunc = [solution_working.vFunc,solution_retired.vFunc] vPfunc = [solution_working.vPfunc,solution_retired.vPfunc] solution_t = DiscreteChoiceSolution(vFunc,vPfunc) solution_t.cFunc = [solution_working.cFunc,solution_retired.cFunc] solution_t.m_underbar = 0 solution_t.kappa_max = np.min(solution_working.kappa_max,solution_retired.kappa_max) if v_best < -1: solution_t.kappa_min = solution_working.kappa_min solution_t.gothic_h = solution_working.gothic_h else: solution_t.kappa_min = solution_retired.kappa_min solution_t.gothic_h = solution_retired.gothic_h solution_t.v_lim_slope = solution_t.kappa_min**(-rho/(1.0-rho)) solution_t.v_lim_intercept = solution_t.gothic_h*solution_t.v_lim_slope return solution_t
def incomeInsuranceSolver(solution_tp1,income_distrib,p_zero_income,survival_prob,beta,rho,R,Gamma,constrained,a_grid,calc_vFunc,cubic_splines): ''' Need to write a real description here. ''' # Solve for optimal consumption in an ordinary period and when income shock insurance is purchased solution_regular = consumptionSavingSolverENDG(solution_tp1,income_distrib,p_zero_income,survival_prob,beta,rho,R,Gamma,constrained,a_grid,calc_vFunc,cubic_splines) solution_insured = consumptionSavingSolverENDG(solution_tp1,insured_income_dist,0.0,survival_prob,beta,rho,R,Gamma-premium,constrained,a_grid,calc_vFunc,cubic_splines) # Construct the solution for this phase vFunc = [solution_regular.vFunc, solution_insured.vFunc] vPfunc = [solution_regular.vPfunc, solution_insured.vPfunc] cFunc = [solution_regular.cFunc, solution_insured.cFunc] solution_t = DiscreteChoiceSolution(vFunc,vPfunc) solution_t.cFunc = cFunc # Add the "pass through" attributes to the solution and report it other_attributes = [key for key in solution_regular.__dict__] other_attributes.remove('vFunc') other_attributes.remove('vPfunc') other_attributes.remove('cFunc') for name in other_attributes: do_string = 'solution_t.' + name + ' = solution_regular.' + name exec(do_string) return solution_t
def occupationalChoiceSolver(solution_tp1,income_distrib,p_zero_income,survival_prob,beta,rho,R,Gamma,constrained,a_grid,calc_vFunc,cubic_splines): ''' Need to write a real description here. ''' # Initialize lists to hold the solution for each occupation vFunc = [] vPfunc = [] cFunc = [] m_underbar = [] gothic_h = [] kappa_min = [] kappa_max = [] v_check = [] # Solve the consumption-saving problem for each possible occupation job_count = len(Gamma) large_m = 100.0*np.max(a_grid) for j in range(job_count): solution_temp = consumptionSavingSolverENDG(solution_tp1,income_distrib[j],p_zero_income[j],survival_prob,beta,rho,R,Gamma[j],constrained,a_grid,calc_vFunc,cubic_splines) vFunc.append(deepcopy(solution_temp.vFunc)) vPfunc.append(deepcopy(solution_temp.vPfunc)) cFunc.append(deepcopy(solution_temp.cFunc)) m_underbar.append(solution_temp.m_underbar) gothic_h.append(solution_temp.gothic_h) kappa_min.append(solution_temp.kappa_min) kappa_max.append(solution_temp.kappa_max) v_check.append(solution_temp.vFunc(large_m)) # Find the best job at "infinity" resources v_check = np.asarray(v_check) v_best = np.argmax(v_check) # Construct the solution for this phase solution_t = DiscreteChoiceSolution(vFunc,vPfunc) solution_t.cFunc = cFunc solution_t.m_underbar = np.max(m_underbar) solution_t.kappa_min = kappa_min[v_best] solution_t.kappa_max = np.min(kappa_max) solution_t.gothic_h = gothic_h[v_best] solution_t.v_lim_slope = solution_t.kappa_min**(-rho/(1.0-rho)) solution_t.v_lim_intercept = solution_t.gothic_h*solution_t.v_lim_slope return solution_t