def updateIncomeProcessAlt(self): tax_rate = (self.income_unemploy*self.p_unemploy)/(self.l_bar*(1.0-self.p_unemploy)) xi_dist = deepcopy(calculateMeanOneLognormalDiscreteApprox(self.xi_N,self.xi_sigma[0])) xi_dist[0] = np.insert(xi_dist[0]*(1.0-self.p_unemploy),0,self.p_unemploy) xi_dist[1] = np.insert(self.l_bar*xi_dist[1]*(1.0-tax_rate),0,self.income_unemploy) psi_dist = calculateMeanOneLognormalDiscreteApprox(self.psi_N,self.psi_sigma[0]) self.income_distrib = [createFlatStateSpaceFromIndepDiscreteProbs(psi_dist,xi_dist)] if self.income_unemploy > 0: self.p_zero_income = [0.0] else: self.p_zero_income = [self.p_unemploy] if not 'income_distrib' in self.time_vary: self.time_vary.append('income_distrib') if not 'p_zero_income' in self.time_vary: self.time_vary.append('p_zero_income')
def updateIncomeProcess(self): ''' Updates this agent's income process based on his own attributes. The function that generates the discrete income process can be swapped out for a different process. ''' original_time = self.time_flow self.timeFwd() perm_shocks = calculateMeanOneLognormalDiscreteApprox(self.psi_N, self.psi_sigma) temp_shocks = addDiscreteOutcomeConstantMean(calculateMeanOneLognormalDiscreteApprox(self.psi_N, self.xi_sigma),self.income_unemploy,self.p_unemploy) self.income_distrib = createFlatStateSpaceFromIndepDiscreteProbs(perm_shocks,temp_shocks) self.p_zero_income = np.sum(temp_shocks[0][temp_shocks[1] == 0]) if not 'income_distrib' in self.time_vary: self.time_vary.append('income_distrib') if not 'p_zero_income' in self.time_vary: self.time_vary.append('p_zero_income') if not original_time: self.timeRev()
def constructLognormalIncomeProcessUnemploymentFailure(parameters): """ Generates a list of discrete approximations to the income process for each life period, from end of life to beginning of life. The process is identical to constructLognormalIncomeProcessUnemployment but for a very tiny possibility that unemployment benefits are not provided. Parameters: ----------- psi_sigma: [float] Array of standard deviations in _permanent_ income uncertainty during the agent's life. psi_N: int The number of approximation points to be used in the equiprobable discrete approximation to the permanent income shock distribution. xi_sigma [float] Array of standard deviations in _temporary_ income uncertainty during the agent's life. xi_N: int The number of approximation points to be used in the equiprobable discrete approximation to the permanent income shock distribution. p_unemploy: float The probability of becoming unemployed p_unemploy_retire: float The probability of not receiving typical retirement income in any retired period T_retire: int The index value i equal to the final working period in the agent's life. If final_work_index < 0 then there is no retirement. income_unemploy: float Income received when unemployed. Often zero. income_unemploy_retire: float Income received while "unemployed" when retired. Often zero. T_total: int Total number of non-terminal periods in this consumer's life. Returns ======= income_distrib: [income distribution] Each element contains the joint distribution of permanent and transitory income shocks, as a set of vectors: psi_shock, xi_shock, and pmf. The first two are the points in the joint state space, and final vector is the joint pmf over those points. For example, psi_shock[20], xi_shock[20], and pmf[20] refers to the (psi, xi) point indexed by 20, with probability p = pmf[20]. p_zero_income: [float] A list of probabilities of receiving exactly zero income in each period. """ # Unpack the parameters from the input psi_sigma = parameters.psi_sigma psi_N = parameters.psi_N xi_sigma = parameters.xi_sigma xi_N = parameters.xi_N T_total = parameters.T_total p_unemploy = parameters.p_unemploy p_unemploy_retire = parameters.p_unemploy_retire T_retire = parameters.T_retire income_unemploy = parameters.income_unemploy income_unemploy_retire = parameters.income_unemploy_retire # Set a small possibility of unemployment benefit failure p_fail = 0.01 income_distrib = [] # Discrete approximation to income process p_zero_income = [] # Probability of zero income in each period of life # Fill out a simple discrete RV for retirement, with value 1.0 (mean of shocks) # in normal times; value 0.0 in "unemployment" times with small prob. if T_retire >= 0: if p_unemploy_retire > 0: retire_perm_income_values = np.array( [1.0, 1.0] ) # Permanent income is deterministic in retirement (2 states for temp income shocks) retire_income_values = np.array([ income_unemploy_retire, (1.0 - p_unemploy_retire * income_unemploy_retire) / (1.0 - p_unemploy_retire) ]) retire_income_probs = np.array( [p_unemploy_retire, 1.0 - p_unemploy_retire]) if income_unemploy_retire > 0: temp_dist = addDiscreteOutcomeConstantMean( [retire_income_values, retire_income_probs], p=(p_fail * p_unemploy_retire), x=0) retire_income_values = temp_dist[0] retire_income_probs = temp_dist[1] retire_perm_income_values = np.array([1.0, 1.0, 1.0]) else: retire_perm_income_values = np.array([1.0]) retire_income_values = np.array([1.0]) retire_income_probs = np.array([1.0]) income_dist_retire = [ retire_perm_income_values, retire_income_values, retire_income_probs ] # Loop to fill in the list of income_distrib random variables. for Tminust in range( T_total ): # Iterate over all periods, counting back from the final period. if T_retire >= 0 and Tminust < T_retire: # Then we are in the "retirement period" and add a retirement income object. income_distrib.append(deepcopy(income_dist_retire)) if income_unemploy_retire == 0: p_zero_income.append(p_unemploy_retire) else: p_zero_income.append(p_fail * p_unemploy_retire) else: # We are in the "working life" periods. temp_xi_dist = calculateMeanOneLognormalDiscreteApprox( N=xi_N, sigma=xi_sigma[Tminust]) if p_unemploy > 0: temp_xi_dist = addDiscreteOutcomeConstantMean( temp_xi_dist, p=p_unemploy, x=income_unemploy) if income_unemploy > 0: temp_xi_dist = addDiscreteOutcomeConstantMean( temp_xi_dist, p=(p_unemploy * p_fail), x=0) temp_psi_dist = calculateMeanOneLognormalDiscreteApprox( N=psi_N, sigma=psi_sigma[Tminust]) income_distrib.append( createFlatStateSpaceFromIndepDiscreteProbs( temp_psi_dist, temp_xi_dist)) if p_unemploy > 0: if income_unemploy == 0: p_zero_income.append(p_unemploy) else: p_zero_income.append(p_unemploy * p_fail) else: p_zero_income.append(0) return income_distrib, p_zero_income