Ejemplo n.º 1
0
 def simMortality(self):
     '''
     Simulates the mortality process, killing off some percentage of agents
     and replacing them with newborn agents.
     
     Parameters
     ----------
     none
         
     Returns
     -------
     none
     '''
     if hasattr(self, 'DiePrb'):
         if self.DiePrb > 0:
             who_dies = drawBernoulli(N=self.Nagents,
                                      p=self.DiePrb,
                                      seed=self.RNG.randint(low=1,
                                                            high=2**31 - 1))
             wealth_all = self.aNow * self.pNow
             who_lives = np.logical_not(who_dies)
             wealth_of_dead = np.sum(wealth_all[who_dies])
             wealth_of_live = np.sum(wealth_all[who_lives])
             R_actuarial = 1.0 + wealth_of_dead / wealth_of_live
             self.aNow[who_dies] = 0.0
             self.pNow[who_dies] = 1.0
             self.aNow = self.aNow * R_actuarial
Ejemplo n.º 2
0
 def getShocks(self):
     '''
     Determine which agents switch from employment to unemployment.  All unemployed agents remain
     unemployed until death.
     
     Parameters
     ----------
     None
     
     Returns
     -------
     None
     '''
     employed = self.eStateNow == 1.0
     N = int(np.sum(employed))
     newly_unemployed = drawBernoulli(N,p=self.UnempPrb,seed=self.RNG.randint(0,2**31-1))
     self.eStateNow[employed] = 1.0 - newly_unemployed
Ejemplo n.º 3
0
 def getShocks(self):
     '''
     Determine which agents switch from employment to unemployment.  All unemployed agents remain
     unemployed until death.
     
     Parameters
     ----------
     None
     
     Returns
     -------
     None
     '''
     employed = self.eStateNow == 1.0
     N = int(np.sum(employed))
     newly_unemployed = drawBernoulli(N,p=self.UnempPrb,seed=self.RNG.randint(0,2**31-1))
     self.eStateNow[employed] = 1.0 - newly_unemployed
Ejemplo n.º 4
0
    def makeIncShkHist(self):
        '''
        Makes histories of simulated income shocks for this consumer type by
        drawing from the discrete income distributions, storing them as attributes
        of self for use by simulation methods.
        
        Parameters
        ----------
        None
        
        Returns
        -------
        None
        '''
        # After running the routine for AggShockConsumerType, just add in updateBeliefHist
        AggShockConsumerType.makeIncShkHist(self)
        orig_time = self.time_flow
        self.timeFwd()
        self.resetRNG()

        # Initialize the shock histories
        updateBeliefHist = np.zeros((self.sim_periods, self.Nagents)) + np.nan
        updateBeliefHist[0, :] = 1.0
        t_idx = 0

        # Loop through each simulated period
        for t in range(1, self.sim_periods):
            updateBeliefHist[t, :] = drawBernoulli(self.Nagents,
                                                   self.updateBeliefProb,
                                                   seed=self.RNG.randint(
                                                       0, 2**31 - 1))
            # Advance the time index, looping if we've run out of income distributions
            t_idx += 1
            if t_idx >= len(self.IncomeDstn):
                t_idx = 0

        # Store the results as attributes of self and restore time to its original flow
        self.updateBeliefHist = updateBeliefHist
        if not orig_time:
            self.timeRev()
Ejemplo n.º 5
0
 def simMortality(self):
     '''
     Simulates the mortality process, killing off some percentage of agents
     and replacing them with newborn agents.
     
     Parameters
     ----------
     none
         
     Returns
     -------
     none
     '''
     if hasattr(self,'DiePrb'):
         if self.DiePrb > 0:
             who_dies = drawBernoulli(N=self.Nagents,p=self.DiePrb,seed=self.RNG.randint(low=1, high=2**31-1))
             wealth_all = self.aNow*self.pNow
             who_lives = np.logical_not(who_dies)
             wealth_of_dead = np.sum(wealth_all[who_dies])
             wealth_of_live = np.sum(wealth_all[who_lives])
             R_actuarial = 1.0 + wealth_of_dead/wealth_of_live
             self.aNow[who_dies] = 0.0
             self.pNow[who_dies] = 1.0
             self.aNow = self.aNow*R_actuarial