Esempio n. 1
0
    def test_small_open(self):
        agent = AggShockConsumerType()
        agent.AgentCount = 100  # Very low number of agents for the sake of speed
        agent.cycles = 0

        # Make agents heterogeneous in their discount factor
        agents = distribute_params(
            agent, "DiscFac", 3, Uniform(bot=0.90, top=0.94)  # Impatient agents
        )

        # Make an economy with those agents living in it
        small_economy = SmallOpenEconomy(
            agents=agents,
            Rfree=1.03,
            wRte=1.0,
            KtoLnow=1.0,
            **copy.copy(init_cobb_douglas)
        )

        small_economy.act_T = 400  # Short simulation history
        small_economy.max_loops = 3  # Give up quickly for the sake of time
        small_economy.make_AggShkHist()  # Simulate a history of aggregate shocks
        small_economy.verbose = False  # Turn off printed messages

        # Give data about the economy to all the agents in it
        for this_type in small_economy.agents:
            this_type.get_economy_data(small_economy)

        small_economy.solve()
    def setUp(self):
        agent = AggShockConsumerType()
        agent.AgentCount = 900  # Very low number of agents for the sake of speed
        agent.cycles = 0

        # Make agents heterogeneous in their discount factor
        self.agents = distribute_params(
            agent, "DiscFac", 3, Uniform(bot=0.90, top=0.94)  # Impatient agents
        )

        # Make an economy with those agents living in it
        self.economy = CobbDouglasEconomy(agents=self.agents)
Esempio n. 3
0
    def getPostStates(self):
        '''
        Slightly extends the base version of this method by recalculating aLvlNow to account for the
        consumer's (potential) misperception about their productivity level.

        Parameters
        ----------
        None

        Returns
        -------
        None
        '''
        AggShockConsumerType.getPostStates(self)
        self.cLvlNow = self.cNrmNow * self.pLvlNow  # True consumption level
        self.aLvlNow = self.mLvlTrueNow - self.cLvlNow  # True asset level
        self.aNrmNow = self.aLvlNow / self.pLvlNow  # Perceived normalized assets
Esempio n. 4
0
class testAggShockConsumerType(unittest.TestCase):

    def setUp(self):
        self.agent = AggShockConsumerType()
        self.agent.cycles = 0

        self.economy = EconomyExample = CobbDouglasEconomy(
            agents=[self.agent])

    def test_economy(self):
        # Make a Cobb-Douglas economy for the agents
        self.economy.makeAggShkHist()  # Simulate a history of aggregate shocks

        # Have the consumers inherit relevant objects from the economy
        self.agent.getEconomyData(self.economy)

        self.agent.solve()
Esempio n. 5
0
    def simBirth(self, which_agents):
        '''
        Makes new consumers for the given indices.  Slightly extends base method by also setting
        pLvlErrNow = 1.0 for new agents, indicating that they correctly perceive their productivity.

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

        Returns
        -------
        None
        '''
        AggShockConsumerType.simBirth(self, which_agents)
        if hasattr(self, 'pLvlErrNow'):
            self.pLvlErrNow[which_agents] = 1.0
        else:
            self.pLvlErrNow = np.ones(self.AgentCount)
Esempio n. 6
0
    def simBirth(self, which_agents):
        '''
        Makes new consumers for the given indices.  Slightly extends base method by also setting
        pLvlErrNow = 1.0 for new agents, indicating that they correctly perceive their productivity.

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

        Returns
        -------
        None
        '''
        AggShockConsumerType.simBirth(self, which_agents)
        if hasattr(self, 'pLvlErrNow'):
            self.pLvlErrNow[which_agents] = 1.0
        else:  # This only triggers at the beginning of the very first simulated period
            self.pLvlErrNow = np.ones(self.AgentCount)
            self.t_since_update = np.zeros(self.AgentCount, dtype=int)
# Solve for the equilibrium aggregate saving rule in a CobbDouglasEconomy
solve_agg_shocks_market = True
# Solve an AggShockMarkovConsumerType's microeconomic problem
solve_markov_micro = False
# Solve for the equilibrium aggregate saving rule in a CobbDouglasMarkovEconomy
solve_markov_market = False
# Solve a simple Krusell-Smith-style two state, two shock model
solve_krusell_smith = True
# Solve a CobbDouglasEconomy with many states, potentially utilizing the "state jumper"
solve_poly_state = False

# ### Example implementation of AggShockConsumerType

if solve_agg_shocks_micro or solve_agg_shocks_market:
    # Make an aggregate shocks consumer type
    AggShockExample = AggShockConsumerType()
    AggShockExample.cycles = 0

    # Make a Cobb-Douglas economy for the agents
    EconomyExample = CobbDouglasEconomy(agents=[AggShockExample])
    EconomyExample.makeAggShkHist()  # Simulate a history of aggregate shocks

    # Have the consumers inherit relevant objects from the economy
    AggShockExample.getEconomyData(EconomyExample)

if solve_agg_shocks_micro:
    # Solve the microeconomic model for the aggregate shocks example type (and display results)
    t_start = process_time()
    AggShockExample.solve()
    t_end = process_time()
    print("Solving an aggregate shocks consumer took " +
Esempio n. 8
0
    if Params.do_sensitivity[7]:  # interest rate sensitivity analysis
        Rfree_list = (np.linspace(1.0, 1.04, 17) /
                      InfiniteType.survival_prob[0]).tolist()
        sensitivityAnalysis('Rfree', Rfree_list, False)

    # =======================================================================
    # ========= FBS aggregate shocks model ==================================
    #========================================================================
    if Params.do_agg_shocks:
        # These are the perpetual youth estimates in case we want to skip estimation (and we do)
        beta_point_estimate = 0.989142
        beta_dist_estimate = 0.985773
        nabla_estimate = 0.0077

        # Make a set of consumer types for the FBS aggregate shocks model
        BaseAggShksType = AggShockConsumerType(**Params.init_agg_shocks)
        agg_shocks_type_list = []
        for j in range(Params.pref_type_count):
            new_type = deepcopy(BaseAggShksType)
            new_type.seed = j
            new_type.resetRNG()
            new_type.makeIncShkHist()
            agg_shocks_type_list.append(new_type)
        if Params.do_beta_dist:
            beta_agg = beta_dist_estimate
            nabla_agg = nabla_estimate
        else:
            beta_agg = beta_point_estimate
            nabla_agg = 0.0
        DiscFac_list_agg = approxUniform(N=Params.pref_type_count,
                                         bot=beta_agg - nabla_agg,
Esempio n. 9
0
    def setUp(self):
        self.agent = AggShockConsumerType()
        self.agent.cycles = 0

        self.economy = EconomyExample = CobbDouglasEconomy(
            agents=[self.agent])