示例#1
0
    def __init__(self, agents=[], tolerance=0.0001, act_T=1000, **kwds):
        '''
        Make a new instance of StickyCobbDouglasEconomy by filling in attributes
        specific to this kind of market.

        Parameters
        ----------
        agents : [ConsumerType]
            List of types of consumers that live in this economy.
        tolerance: float
            Minimum acceptable distance between "dynamic rules" to consider the
            solution process converged.  Distance depends on intercept and slope
            of the log-linear "next capital ratio" function.
        act_T : int
            Number of periods to simulate when making a history of of the market.

        Returns
        -------
        None
        '''
        CobbDouglasEconomy.__init__(self,
                                    agents=agents,
                                    tolerance=tolerance,
                                    act_T=act_T,
                                    **kwds)
        self.reap_vars = ['aLvlNow', 'pLvlTrue']
    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)
class testAggShockConsumerType(unittest.TestCase):
    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 = distributeParams(
            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)

    def test_distributeParams(self):
        self.assertEqual(self.agents[1].AgentCount, 300)

    def test_agent(self):
        # Have one consumer type inherit relevant objects from the economy,
        # then solve their microeconomic problem
        self.agents[0].getEconomyData(self.economy)
        self.agents[0].solve()
        self.assertAlmostEqual(
            self.agents[0].solution[0].cFunc(10.0, self.economy.MSS),
            3.229078148576943)

    def test_macro(self):
        self.economy.act_T = 400  # Short simulation history
        self.economy.max_loops = 3  # Give up quickly for the sake of time
        self.economy.makeAggShkHist()  # Simulate a history of aggregate shocks
        self.economy.verbose = False  # Turn off printed messages

        # Give data about the economy to all the agents in it
        for this_type in self.economy.agents:
            this_type.getEconomyData(self.economy)
        self.economy.solve(
        )  # Solve for the general equilibrium of the economy

        self.economy.AFunc = self.economy.dynamics.AFunc
        self.assertAlmostEqual(self.economy.AFunc.slope, 1.116259456228145)

        self.assertAlmostEqual(self.economy.history["MaggNow"][10],
                               7.456324335623432)
# 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 " +
          mystr(t_end - t_start) + " seconds.")
    print(
        "Consumption function at each aggregate market resources-to-labor ratio gridpoint:"
    )
示例#5
0
            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,
                                         top=beta_agg + nabla_agg)[1]
        assignBetaDistribution(agg_shocks_type_list, DiscFac_list_agg)

        # Make a market for solving the FBS aggregate shocks model
        agg_shocks_market = CobbDouglasEconomy(
            agents=agg_shocks_type_list,
            act_T=Params.sim_periods_agg_shocks,
            tolerance=0.0001,
            **Params.aggregate_params)
        agg_shocks_market.makeAggShkHist()

        # Edit the consumer types so they have the right data
        for this_type in agg_shocks_market.agents:
            this_type.p_init = drawMeanOneLognormal(N=this_type.Nagents,
                                                    sigma=0.9,
                                                    seed=0)
            this_type.getEconomyData(agg_shocks_market)

        # Solve the aggregate shocks version of the model
        t_start = time()
        agg_shocks_market.solve()
        t_end = time()
示例#6
0
    def setUp(self):
        self.agent = AggShockConsumerType()
        self.agent.cycles = 0

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