Example #1
0
    def getRisky(self):
        '''
        Sets the attribute RiskyNow as a single draw from a lognormal distribution.
        Uses the attributes RiskyAvgTrue and RiskyStdTrue if RiskyAvg is time-varying,
        else just uses the single values from RiskyAvg and RiskyStd.
        
        Parameters
        ----------
        None

        Returns
        -------
        None
        '''
        if 'RiskyDstn' in self.time_vary:
            RiskyAvg = self.RiskyAvgTrue
            RiskyStd = self.RiskyStdTrue
        else:
            RiskyAvg = self.RiskyAvg
            RiskyStd = self.RiskyStd
        RiskyAvgSqrd = RiskyAvg**2
        RiskyVar = RiskyStd**2

        mu = np.log(RiskyAvg / (np.sqrt(1. + RiskyVar / RiskyAvgSqrd)))
        sigma = np.sqrt(np.log(1. + RiskyVar / RiskyAvgSqrd))
        self.RiskyNow = drawLognormal(1,
                                      mu=mu,
                                      sigma=sigma,
                                      seed=self.RNG.randint(0, 2**31 - 1))
    def simBirth(self, which_agents):
        '''
        Makes new consumers for the given indices.  Initialized variables include aNrm, as
        well as time variables t_age and t_cycle.  Normalized assets are drawn from a lognormal
        distributions given by aLvlInitMean and aLvlInitStd.

        Parameters
        ----------
        which_agents : np.array(Bool)
            Boolean array of size self.AgentCount indicating which agents should be "born".

        Returns
        -------
        None
        '''
        # Get and store states for newly born agents
        N = np.sum(which_agents)  # Number of new consumers to make
        self.aLvlNow[which_agents] = drawLognormal(N,
                                                   mu=self.aLvlInitMean,
                                                   sigma=self.aLvlInitStd,
                                                   seed=self.RNG.randint(
                                                       0, 2**31 - 1))
        self.eStateNow[which_agents] = 1.0  # Agents are born employed
        self.t_age[
            which_agents] = 0  # How many periods since each agent was born
        self.t_cycle[
            which_agents] = 0  # Which period of the cycle each agent is currently in
        return None
Example #3
0
 def test_drawLognormal(self):
     self.assertEqual(simulation.drawLognormal(1)[0], 5.836039190663969)
Example #4
0
# Make riskless return factor very low so that nobody invests in it.
mpc_dict['Rfree'] = 0.01
# Make the agent less risk averse
mpc_dict['CRRA'] = 2
# Do away with probability of death
mpc_dict['LivPrb'] = [1] * dict_portfolio['T_cycle']

# Risky returns
mu = 0.05
std = 0.1

# Construct the distribution approximation for integration
RiskyDstnFunc = lambda count: approxLognormal(count, mu=mu, sigma=std)
# Contruct function for drawing returns
RiskyDrawFunc = lambda seed: drawLognormal(1, mu=mu, sigma=std, seed=seed)

mpc_dict['approxRiskyDstn'] = RiskyDstnFunc
mpc_dict['drawRiskyFunc'] = RiskyDrawFunc

agent = cpm.PortfolioConsumerType(**mpc_dict)
agent.cylces = 0
agent.solve()

# %% Compute the theoretical MPC (for when there is no labor income)

# First extract some parameter values that will be used
crra = agent.CRRA
sigma_r = std
goth_r = mu + sigma_r**2 / 2
beta = agent.DiscFac