def update(self): ''' Use primitive parameters (and perfect foresight calibrations) to make interest factor and wage rate functions (of capital to labor ratio), as well as discrete approximations to the aggregate shock distributions. Parameters ---------- none Returns ------- none ''' self.kSS = ((self.CRRA/self.DiscFac - (1.0-self.DeprFac))/self.CapShare)**(1.0/(self.CapShare-1.0)) self.KtoYSS = self.kSS**(1.0-self.CapShare) self.wRteSS = (1.0-self.CapShare)*self.kSS**(self.CapShare) self.convertKtoY = lambda KtoY : KtoY**(1.0/(1.0 - self.CapShare)) # converts K/Y to K/L self.Rfunc = lambda k : (1.0 + self.CapShare*k**(self.CapShare-1.0) - self.DeprFac) self.wFunc = lambda k : ((1.0-self.CapShare)*k**(self.CapShare))/self.wRteSS self.KtoLnow_init = self.kSS self.RfreeNow_init = self.Rfunc(self.kSS) self.wRteNow_init = self.wFunc(self.kSS) self.PermShkAggNow_init = 1.0 self.TranShkAggNow_init = 1.0 self.TranShkAggDstn = approxMeanOneLognormal(sigma=self.TranShkAggStd,N=self.TranShkAggCount) self.PermShkAggDstn = approxMeanOneLognormal(sigma=self.PermShkAggStd,N=self.PermShkAggCount) self.AggShkDstn = combineIndepDstns(self.PermShkAggDstn,self.TranShkAggDstn) self.kNextFunc = CapitalEvoRule(self.intercept_prev,self.slope_prev)
def updateIncomeProcessAlt(self): ''' An alternative method for constructing the income process in the infinite horizon model, where the labor supply l_bar creates a small oddity. Parameters ---------- none Returns ------- none ''' tax_rate = (self.IncUnemp * self.UnempPrb) / (self.l_bar * (1.0 - self.UnempPrb)) TranShkDstn = deepcopy( approxMeanOneLognormal(self.TranShkCount, sigma=self.TranShkStd[0], tail_N=0)) TranShkDstn[0] = np.insert(TranShkDstn[0] * (1.0 - self.UnempPrb), 0, self.UnempPrb) TranShkDstn[1] = np.insert( self.l_bar * TranShkDstn[1] * (1.0 - tax_rate), 0, self.IncUnemp) PermShkDstn = approxMeanOneLognormal(self.PermShkCount, sigma=self.PermShkStd[0], tail_N=0) self.IncomeDstn = [combineIndepDstns(PermShkDstn, TranShkDstn)] self.TranShkDstn = TranShkDstn self.PermShkDstn = PermShkDstn self.addToTimeVary('IncomeDstn')
def update(self): ''' Use primitive parameters to set basic objects. This is an extremely stripped-down version of update for CobbDouglasEconomy. Parameters ---------- none Returns ------- none ''' self.kSS = 1.0 self.MSS = 1.0 self.KtoLnow_init = self.kSS self.Rfunc = ConstantFunction(self.Rfree) self.wFunc = ConstantFunction(self.wRte) self.RfreeNow_init = self.Rfunc(self.kSS) self.wRteNow_init = self.wFunc(self.kSS) self.MaggNow_init = self.kSS self.AaggNow_init = self.kSS self.PermShkAggNow_init = 1.0 self.TranShkAggNow_init = 1.0 self.TranShkAggDstn = approxMeanOneLognormal(sigma=self.TranShkAggStd,N=self.TranShkAggCount) self.PermShkAggDstn = approxMeanOneLognormal(sigma=self.PermShkAggStd,N=self.PermShkAggCount) self.AggShkDstn = combineIndepDstns(self.PermShkAggDstn,self.TranShkAggDstn) self.AFunc = ConstantFunction(1.0)
def updateIncomeProcess(self): ''' An alternative method for constructing the income process in the infinite horizon model. Parameters ---------- none Returns ------- none ''' if self.cycles == 0: tax_rate = (self.IncUnemp * self.UnempPrb) / ( (1.0 - self.UnempPrb) * self.IndL) TranShkDstn = deepcopy( approxMeanOneLognormal(self.TranShkCount, sigma=self.TranShkStd[0], tail_N=0)) TranShkDstn[0] = np.insert(TranShkDstn[0] * (1.0 - self.UnempPrb), 0, self.UnempPrb) TranShkDstn[1] = np.insert( TranShkDstn[1] * (1.0 - tax_rate) * self.IndL, 0, self.IncUnemp) PermShkDstn = approxMeanOneLognormal(self.PermShkCount, sigma=self.PermShkStd[0], tail_N=0) self.IncomeDstn = [combineIndepDstns(PermShkDstn, TranShkDstn)] self.TranShkDstn = TranShkDstn self.PermShkDstn = PermShkDstn self.addToTimeVary('IncomeDstn') else: # Do the usual method if this is the lifecycle model EstimationAgentClass.updateIncomeProcess(self)
def update(self): ''' Use primitive parameters to set basic objects. This is an extremely stripped-down version of update for CobbDouglasEconomy. Parameters ---------- none Returns ------- none ''' self.kSS = 1.0 self.MSS = 1.0 self.KtoLnow_init = self.kSS self.Rfunc = ConstantFunction(self.Rfree) self.wFunc = ConstantFunction(self.wRte) self.RfreeNow_init = self.Rfunc(self.kSS) self.wRteNow_init = self.wFunc(self.kSS) self.MaggNow_init = self.kSS self.AaggNow_init = self.kSS self.PermShkAggNow_init = 1.0 self.TranShkAggNow_init = 1.0 self.TranShkAggDstn = approxMeanOneLognormal(sigma=self.TranShkAggStd, N=self.TranShkAggCount) self.PermShkAggDstn = approxMeanOneLognormal(sigma=self.PermShkAggStd, N=self.PermShkAggCount) self.AggShkDstn = combineIndepDstns(self.PermShkAggDstn, self.TranShkAggDstn) self.AFunc = ConstantFunction(1.0)
def updatePrefShockProcess(self): ''' Make a discrete preference shock structure for each period in the cycle for this agent type, storing them as attributes of self for use in the solution (and other methods). Parameters ---------- none Returns ------- none ''' time_orig = self.time_flow self.timeFwd() PrefShkDstn = [] # discrete distributions of preference shocks for t in range(len(self.PrefShkStd)): PrefShkStd = self.PrefShkStd[t] PrefShkDstn.append(approxMeanOneLognormal(N=self.PrefShkCount, sigma=PrefShkStd,tail_N=self.PrefShk_tail_N)) # Store the preference shocks in self (time-varying) and restore time flow self.PrefShkDstn = PrefShkDstn self.addToTimeVary('PrefShkDstn') if not time_orig: self.timeRev()
def updatePrefShockProcess(self): ''' Make a discrete preference shock structure for each period in the cycle for this agent type, storing them as attributes of self for use in the solution (and other methods). Parameters ---------- none Returns ------- none ''' time_orig = self.time_flow self.timeFwd() PrefShkDstn = [] # discrete distributions of preference shocks for t in range(len(self.PrefShkStd)): PrefShkStd = self.PrefShkStd[t] PrefShkDstn.append( approxMeanOneLognormal(N=self.PrefShkCount, sigma=PrefShkStd, tail_N=self.PrefShk_tail_N)) # Store the preference shocks in self (time-varying) and restore time flow self.PrefShkDstn = PrefShkDstn self.addToTimeVary('PrefShkDstn') if not time_orig: self.timeRev()
def update(self): ''' Use primitive parameters (and perfect foresight calibrations) to make interest factor and wage rate functions (of capital to labor ratio), as well as discrete approximations to the aggregate shock distributions. Parameters ---------- none Returns ------- none ''' self.kSS = ((self.CRRA/self.DiscFac - (1.0-self.DeprFac))/self.CapShare)**(1.0/(self.CapShare-1.0)) self.KtoYSS = self.kSS**(1.0-self.CapShare) self.wRteSS = (1.0-self.CapShare)*self.kSS**(self.CapShare) self.convertKtoY = lambda KtoY : KtoY**(1.0/(1.0 - self.CapShare)) # converts K/Y to K/L self.Rfunc = lambda k : (1.0 + self.CapShare*k**(self.CapShare-1.0) - self.DeprFac) self.wFunc = lambda k : ((1.0-self.CapShare)*k**(self.CapShare))/self.wRteSS self.KtoLnow_init = self.kSS self.RfreeNow_init = self.Rfunc(self.kSS) self.wRteNow_init = self.wFunc(self.kSS) self.PermShkAggNow_init = 1.0 self.TranShkAggNow_init = 1.0 # self.TranShkAggDstn = approxMeanOneLognormal(sigma=self.TranShkAggStd,N=self.TranShkAggCount) self.PermShkAggDstn = approxMeanOneLognormal(sigma=self.PermShkAggStd,N=self.PermShkAggCount) # self.AggShkDstn = combineIndepDstns(self.PermShkAggDstn,self.TranShkAggDstn) self.AggShkDstn = self.PermShkAggDstn self.kNextFunc = CapitalEvoRule(self.intercept_prev,self.slope_prev)
def updateIncomeProcessAlt(self): ''' An alternative method for constructing the income process in the infinite horizon model, where the labor supply l_bar creates a small oddity. Parameters ---------- none Returns ------- none ''' tax_rate = (self.IncUnemp*self.UnempPrb)/(self.l_bar*(1.0-self.UnempPrb)) TranShkDstn = deepcopy(approxMeanOneLognormal(self.TranShkCount,sigma=self.TranShkStd[0],tail_N=0)) TranShkDstn[0] = np.insert(TranShkDstn[0]*(1.0-self.UnempPrb),0,self.UnempPrb) TranShkDstn[1] = np.insert(self.l_bar*TranShkDstn[1]*(1.0-tax_rate),0,self.IncUnemp) PermShkDstn = approxMeanOneLognormal(self.PermShkCount,sigma=self.PermShkStd[0],tail_N=0) self.IncomeDstn = [combineIndepDstns(PermShkDstn,TranShkDstn)] self.TranShkDstn = TranShkDstn self.PermShkDstn = PermShkDstn self.addToTimeVary('IncomeDstn')
def updateIncomeProcess(self): ''' An alternative method for constructing the income process in the infinite horizon model. Parameters ---------- none Returns ------- none ''' if self.cycles == 0: tax_rate = (self.IncUnemp*self.UnempPrb)/((1.0-self.UnempPrb)*self.IndL) TranShkDstn = deepcopy(approxMeanOneLognormal(self.TranShkCount,sigma=self.TranShkStd[0],tail_N=0)) TranShkDstn[0] = np.insert(TranShkDstn[0]*(1.0-self.UnempPrb),0,self.UnempPrb) TranShkDstn[1] = np.insert(TranShkDstn[1]*(1.0-tax_rate)*self.IndL,0,self.IncUnemp) PermShkDstn = approxMeanOneLognormal(self.PermShkCount,sigma=self.PermShkStd[0],tail_N=0) self.IncomeDstn = [combineIndepDstns(PermShkDstn,TranShkDstn)] self.TranShkDstn = TranShkDstn self.PermShkDstn = PermShkDstn self.addToTimeVary('IncomeDstn') else: # Do the usual method if this is the lifecycle model EstimationAgentClass.updateIncomeProcess(self)
def getShocks(self): ''' Gets permanent and transitory income shocks for this period as well as preference shocks. Parameters ---------- None Returns ------- None ''' IndShockConsumerType.getShocks(self) # Get permanent and transitory income shocks PrefShkNow = np.zeros(self.AgentCount) # Initialize shock array for t in range(self.T_cycle): these = t == self.t_cycle N = np.sum(these) if N > 0: PrefShkNow[these] = self.RNG.permutation(approxMeanOneLognormal(N,sigma=self.PrefShkStd[t])[1]) self.PrefShkNow = PrefShkNow
def makePrefShkHist(self): ''' Makes histories of simulated preference shocks for this consumer type by drawing from the shock distribution's true lognormal form. Parameters ---------- none Returns ------- none ''' orig_time = self.time_flow self.timeFwd() self.resetRNG() # Initialize the preference shock history PrefShkHist = np.zeros((self.sim_periods, self.Nagents)) + np.nan PrefShkHist[0, :] = 1.0 t_idx = 0 # Make discrete distributions of preference shocks to permute base_dstns = [] for t_idx in range(len(self.PrefShkStd)): temp_dstn = approxMeanOneLognormal(N=self.Nagents, sigma=self.PrefShkStd[t_idx]) base_dstns.append(temp_dstn[1]) # only take values, not probs # Fill in the preference shock history for t in range(1, self.sim_periods): dstn_now = base_dstns[t_idx] PrefShkHist[t, :] = self.RNG.permutation(dstn_now) t_idx += 1 if t_idx >= len(self.PrefShkStd): t_idx = 0 self.PrefShkHist = PrefShkHist if not orig_time: self.timeRev()
def makePrefShkHist(self): ''' Makes histories of simulated preference shocks for this consumer type by drawing from the shock distribution's true lognormal form. Parameters ---------- none Returns ------- none ''' orig_time = self.time_flow self.timeFwd() self.resetRNG() # Initialize the preference shock history PrefShkHist = np.zeros((self.sim_periods,self.Nagents)) + np.nan PrefShkHist[0,:] = 1.0 t_idx = 0 # Make discrete distributions of preference shocks to permute base_dstns = [] for t_idx in range(len(self.PrefShkStd)): temp_dstn = approxMeanOneLognormal(N=self.Nagents,sigma=self.PrefShkStd[t_idx]) base_dstns.append(temp_dstn[1]) # only take values, not probs # Fill in the preference shock history for t in range(1,self.sim_periods): dstn_now = base_dstns[t_idx] PrefShkHist[t,:] = self.RNG.permutation(dstn_now) t_idx += 1 if t_idx >= len(self.PrefShkStd): t_idx = 0 self.PrefShkHist = PrefShkHist if not orig_time: self.timeRev()
def constructLognormalIncomeAndPreferenceProcess(parameters): ''' Generates a list of discrete approximations to the income and preference shock process . Permanent shocks are mean one lognormally distributed with standard deviation PermShkStd. Transitory shocks are mean one lognormally distributed Parameters (passed as attributes of the input parameters) ---------- PermShkStd : [float] List of standard deviations in log permanent income uncertainty during the agent's life. PermShkCount : int The number of approximation points to be used in the discrete approxima- tion to the permanent income shock distribution. TranShkStd : [float] List of standard deviations in log transitory income uncertainty during the agent's life. TranShkCount : int The number of approximation points to be used in the discrete approxima- tion to the permanent income shock distribution. PrefShkStd : [float] List of standard deviations in log preference uncertainty during the agent's life. PrefShkCount : int The number of approximation points to be used in the discrete approxima- tion to the preference shock distribution. Returns ------- IncomeAndPrefDstn : [[np.array]] A list with T_cycle elements, each of which is a list of four arrays representing a discrete approximation to the income and preference process in a period. Order: probabilities, permanent shocks, transitory shocks, preference shocks. PermShkDstn : [[np.array]] A list with T_cycle elements, each of which is a list of two arrays representing a discrete approximation to the permanent income shocks. TranShkDstn : [[np.array]] A list with T_cycle elements, each of which is a list of two arrays representing a discrete approximation to the transitory income shocks. PrefShkDstn : [[np.array]] A list with T_cycle elements, each of which is a list of two arrays representing a discrete approximation to the preference shocks. ''' # Unpack the parameters from the input PermShkStd = parameters.PermShkStd PermShkCount = parameters.PermShkCount TranShkStd = parameters.TranShkStd TranShkCount = parameters.TranShkCount PrefShkStd = parameters.PrefShkStd PrefShkCount = parameters.PrefShkCount T_cycle = 1 UnempPrb = parameters.UnempPrb IncUnemp = parameters.IncUnemp IncomeDstn = [] # Discrete approximations to income process in each period PermShkDstn = [] # Discrete approximations to permanent income shocks TranShkDstn = [] # Discrete approximations to transitory income shocks PrefShkDstn = [] # Discrete approximations to preference shocks t = 0 TranShkDstn_t = approxMeanOneLognormal(N=TranShkCount, sigma=TranShkStd[t], tail_N=0) if UnempPrb > 0: TranShkDstn_t = addDiscreteOutcomeConstantMean(TranShkDstn_t, p=UnempPrb, x=IncUnemp) #add in a shock at zero to impose natural borrowing constraint TranShkDstn_t = addDiscreteOutcomeConstantMean(TranShkDstn_t, p=0.000000001, x=0.0) PermShkDstn_t = approxMeanOneLognormal(N=PermShkCount, sigma=PermShkStd[t], tail_N=0) PrefShkDstn_t = approxMeanOneLognormal(N=PrefShkCount, sigma=PrefShkStd[t], tail_N=0) IncomeDstn.append( combineIndepDstns(PermShkDstn_t, TranShkDstn_t, PrefShkDstn_t)) # mix the independent distributions PermShkDstn.append(PermShkDstn_t) TranShkDstn.append(TranShkDstn_t) PrefShkDstn.append(PrefShkDstn_t) return IncomeDstn, PermShkDstn, TranShkDstn, PrefShkDstn
------- none ''' tax_rate = (self.IncUnemp*self.UnempPrb)/(self.l_bar*(1.0-self.UnempPrb)) <<<<<<< HEAD TranShkDstn = deepcopy(approxLognormal(self.TranShkCount,sigma=self.TranShkStd[0],tail_N=0)) TranShkDstn[0] = np.insert(TranShkDstn[0]*(1.0-self.UnempPrb),0,self.UnempPrb) TranShkDstn[1] = np.insert(self.l_bar*TranShkDstn[1]*(1.0-tax_rate),0,self.IncUnemp) PermShkDstn = approxLognormal(self.PermShkCount,sigma=self.PermShkStd[0],tail_N=0) self.IncomeDstn = [combineIndepDstns(PermShkDstn,TranShkDstn)] self.TranShkDstn = TranShkDstn self.PermShkDstn = PermShkDstn if not 'IncomeDstn' in self.time_vary: self.time_vary.append('IncomeDstn') ======= TranShkDstn = deepcopy(approxMeanOneLognormal(self.TranShkCount,sigma=self.TranShkStd[0],tail_N=0)) TranShkDstn[0] = np.insert(TranShkDstn[0]*(1.0-self.UnempPrb),0,self.UnempPrb) TranShkDstn[1] = np.insert(self.l_bar*TranShkDstn[1]*(1.0-tax_rate),0,self.IncUnemp) PermShkDstn = approxMeanOneLognormal(self.PermShkCount,sigma=self.PermShkStd[0],tail_N=0) self.IncomeDstn = [combineIndepDstns(PermShkDstn,TranShkDstn)] self.TranShkDstn = TranShkDstn self.PermShkDstn = PermShkDstn self.addToTimeVary('IncomeDstn') >>>>>>> eeb37f24755d0c683c9d9efbe5e7447425c98b86 def assignBetaDistribution(type_list,DiscFac_list): ''' Assigns the discount factors in DiscFac_list to the types in type_list. If there is heterogeneity beyond the discount factor, then the same DiscFac is assigned to consecutive types.