def getEconomyData(self,Economy): ''' Imports economy-determined objects into self from a Market. Instances of AggShockConsumerType "live" in some macroeconomy that has attributes relevant to their microeconomic model, like the relationship between the capital-to-labor ratio and the interest and wage rates; this method imports those attributes from an "economy" object and makes them attributes of the ConsumerType. Parameters ---------- Economy : Market The "macroeconomy" in which this instance "lives". Might be of the subclass CobbDouglasEconomy, which has methods to generate the relevant attributes. Returns ------- None ''' self.a_init = Economy.KtoYSS*np.ones(self.Nagents) # Initialize assets to steady state self.kGrid = Economy.kSS*self.kGridBase # Capital ratio grid adjusted around SS ratio self.kNextFunc = Economy.kNextFunc # Next period's capital ratio as function of current ratio self.Rfunc = Economy.Rfunc # Interest factor as function of capital ratio self.wFunc = Economy.wFunc # (Normalized) wage rate as function of capital ratio IncomeDstnWithAggShks = combineIndepDstns(self.PermShkDstn,self.TranShkDstn,Economy.PermShkAggDstn) #Economy.TranShkAggDstn self.IncomeDstn = [IncomeDstnWithAggShks] # Discrete income distribution with aggregate and idiosyncratic shocks self.DiePrb = 1.0 - self.LivPrb[0] # Only relevant for simulating with mortality self.addToTimeInv('kGrid','kNextFunc','Rfunc', 'wFunc')
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 getEconomyData(self, Economy): ''' Imports economy-determined objects into self from a Market. Instances of AggShockConsumerType "live" in some macroeconomy that has attributes relevant to their microeconomic model, like the relationship between the capital-to-labor ratio and the interest and wage rates; this method imports those attributes from an "economy" object and makes them attributes of the ConsumerType. Parameters ---------- Economy : Market The "macroeconomy" in which this instance "lives". Might be of the subclass CobbDouglasEconomy, which has methods to generate the relevant attributes. Returns ------- None ''' self.a_init = Economy.KtoYSS * np.ones( self.Nagents) # Initialize assets to steady state self.kGrid = Economy.kSS * self.kGridBase # Capital ratio grid adjusted around SS ratio self.kNextFunc = Economy.kNextFunc # Next period's capital ratio as function of current ratio self.Rfunc = Economy.Rfunc # Interest factor as function of capital ratio self.wFunc = Economy.wFunc # (Normalized) wage rate as function of capital ratio IncomeDstnWithAggShks = combineIndepDstns( self.PermShkDstn, self.TranShkDstn, Economy.PermShkAggDstn) #Economy.TranShkAggDstn self.IncomeDstn = [ IncomeDstnWithAggShks ] # Discrete income distribution with aggregate and idiosyncratic shocks self.DiePrb = 1.0 - self.LivPrb[ 0] # Only relevant for simulating with mortality self.addToTimeInv('kGrid', 'kNextFunc', 'Rfunc', 'wFunc')
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 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 getEconomyData(self,Economy): ''' Imports economy-determined objects into self from a Market. Instances of AggShockConsumerType "live" in some macroeconomy that has attributes relevant to their microeconomic model, like the relationship between the capital-to-labor ratio and the interest and wage rates; this method imports those attributes from an "economy" object and makes them attributes of the ConsumerType. Parameters ---------- Economy : Market The "macroeconomy" in which this instance "lives". Might be of the subclass CobbDouglasEconomy, which has methods to generate the relevant attributes. Returns ------- None ''' self.kInit = Economy.kSS # Initialize simulation assets to steady state self.aNrmInitMean = np.log(0.00000001) # Initialize newborn assets to nearly zero self.Mgrid = Economy.MSS*self.MgridBase # Aggregate market resources grid adjusted around SS capital ratio self.AFunc = Economy.AFunc # Next period's aggregate savings function self.Rfunc = Economy.Rfunc # Interest factor as function of capital ratio self.wFunc = Economy.wFunc # Wage rate as function of capital ratio self.DeprFac = Economy.DeprFac # Rate of capital depreciation IncomeDstnWithAggShks = combineIndepDstns(self.PermShkDstn,self.TranShkDstn,Economy.PermShkAggDstn,Economy.TranShkAggDstn) self.IncomeDstn = [IncomeDstnWithAggShks] # Discrete income distribution with aggregate and idiosyncratic shocks self.addToTimeInv('Mgrid','AFunc','Rfunc', 'wFunc','DeprFac')
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 = ((1.0 / 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.RfreeSS = (1.0 + self.CapShare * self.kSS**(self.CapShare - 1.0) - self.DeprFac) self.MSS = self.kSS * (self.RfreeSS + self.DeprFac) + self.wRteSS 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.KtoLnow_init = self.kSS self.MaggNow_init = self.kSS self.AaggNow_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.AFunc = AggregateSavingRule(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 getEconomyData(self, Economy): ''' Imports economy-determined objects into self from a Market. Instances of AggShockConsumerType "live" in some macroeconomy that has attributes relevant to their microeconomic model, like the relationship between the capital-to-labor ratio and the interest and wage rates; this method imports those attributes from an "economy" object and makes them attributes of the ConsumerType. Parameters ---------- Economy : Market The "macroeconomy" in which this instance "lives". Might be of the subclass CobbDouglasEconomy, which has methods to generate the relevant attributes. Returns ------- None ''' self.kInit = Economy.kSS # Initialize simulation assets to steady state self.aNrmInitMean = np.log( 0.00000001) # Initialize newborn assets to nearly zero self.Mgrid = Economy.MSS * self.MgridBase # Aggregate market resources grid adjusted around SS capital ratio self.AFunc = Economy.AFunc # Next period's aggregate savings function self.Rfunc = Economy.Rfunc # Interest factor as function of capital ratio self.wFunc = Economy.wFunc # Wage rate as function of capital ratio self.DeprFac = Economy.DeprFac # Rate of capital depreciation IncomeDstnWithAggShks = combineIndepDstns(self.PermShkDstn, self.TranShkDstn, Economy.PermShkAggDstn, Economy.TranShkAggDstn) self.IncomeDstn = [ IncomeDstnWithAggShks ] # Discrete income distribution with aggregate and idiosyncratic shocks self.addToTimeInv('Mgrid', 'AFunc', 'Rfunc', 'wFunc', 'DeprFac')
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 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
Parameters ---------- none Returns ------- 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