Пример #1
0
def makeCSTWresults(DiscFac, nabla, save_name=None):
    '''
    Produces a variety of results for the cstwMPC paper (usually after estimating).

    Parameters
    ----------
    DiscFac : float
        Center of the uniform distribution of discount factors
    nabla : float
        Width of the uniform distribution of discount factors
    save_name : string
        Name to save the calculated results, for later use in producing figures
        and tables, etc.

    Returns
    -------
    none
    '''
    DiscFac_list = approxUniform(N=Params.pref_type_count,
                                 bot=DiscFac - nabla,
                                 top=DiscFac + nabla)[1]
    assignBetaDistribution(est_type_list, DiscFac_list)
    multiThreadCommandsFake(est_type_list, beta_point_commands)

    lorenz_distance = np.sqrt(betaDistObjective(nabla))

    makeCSTWstats(DiscFac, nabla, est_type_list, Params.age_weight_all,
                  lorenz_distance, save_name)
Пример #2
0
def calcKappaMean(DiscFac, nabla):
    '''
    Calculates the average MPC for the given parameters.  This is a very small
    sub-function of sensitivityAnalysis.

    Parameters
    ----------
    DiscFac : float
        Center of the uniform distribution of discount factors
    nabla : float
        Width of the uniform distribution of discount factors

    Returns
    -------
    kappa_all : float
        Average marginal propensity to consume in the population.
    '''
    DiscFac_list = approxUniform(N=Params.pref_type_count,
                                 bot=DiscFac - nabla,
                                 top=DiscFac + nabla)[1]
    assignBetaDistribution(est_type_list, DiscFac_list)
    multiThreadCommandsFake(est_type_list, beta_point_commands)

    kappa_all = calcWeightedAvg(
        np.vstack((this_type.kappa_history for this_type in est_type_list)),
        np.tile(Params.age_weight_all / float(Params.pref_type_count),
                Params.pref_type_count))
    return kappa_all
Пример #3
0
def simulateKYratioDifference(DiscFac, nabla, N, type_list, weights,
                              total_output, target):
    '''
    Assigns a uniform distribution over DiscFac with width 2*nabla and N points, then
    solves and simulates all agent types in type_list and compares the simuated
    K/Y ratio to the target K/Y ratio.

    Parameters
    ----------
    DiscFac : float
        Center of the uniform distribution of discount factors.
    nabla : float
        Width of the uniform distribution of discount factors.
    N : int
        Number of discrete consumer types.
    type_list : [cstwMPCagent]
        List of agent types to solve and simulate after assigning discount factors.
    weights : np.array
        Age-conditional array of population weights.
    total_output : float
        Total output of the economy, denominator for the K/Y calculation.
    target : float
        Target level of capital-to-output ratio.

    Returns
    -------
    my_diff : float
        Difference between simulated and target capital-to-output ratios.
    '''
    if type(DiscFac) in (list, np.ndarray, np.array):
        DiscFac = DiscFac[0]
    DiscFac_list = approxUniform(N, DiscFac - nabla, DiscFac +
                                 nabla)[1]  # only take values, not probs
    assignBetaDistribution(type_list, DiscFac_list)
    multiThreadCommandsFake(type_list, beta_point_commands)
    my_diff = calculateKYratioDifference(
        np.vstack((this_type.W_history for this_type in type_list)),
        np.tile(weights / float(N), N), total_output, target)
    return my_diff
Пример #4
0
 def test_multiThreadCommandsFake(self):
     # check None return if it passes
     self.assertIsNone(multiThreadCommandsFake(self.agents, ["solve()"]))
     # check if an undefined method of agent is called
     self.assertRaises(AttributeError, multiThreadCommandsFake, self.agents,
                       ["foobar"])
Пример #5
0
    BasicType.vFuncBool = False  # just in case it was set to True above
    my_agent_list = []
    CRRA_list = np.linspace(
        1, 8, type_count)  # All the values that CRRA will take on
    for i in range(type_count):
        this_agent = deepcopy(BasicType)  # Make a new copy of the basic type
        this_agent.assignParameters(
            CRRA=CRRA_list[i])  # Give it a unique CRRA value
        my_agent_list.append(this_agent)  # Addd it to the list of agent types

    # Make a list of commands to be run in parallel; these should be methods of ConsumerType
    do_this_stuff = ['updateSolutionTerminal()', 'solve()', 'unpackcFunc()']

    # Solve the model for each type by looping over the types (not multithreading)
    start_time = clock()
    multiThreadCommandsFake(my_agent_list,
                            do_this_stuff)  # Fake multithreading, just loops
    end_time = clock()
    print('Solving ' + str(type_count) +
          ' types without multithreading took ' +
          mystr(end_time - start_time) + ' seconds.')

    # Plot the consumption functions for all types on one figure
    plotFuncs([this_type.cFunc[0] for this_type in my_agent_list], 0, 5)

    # Delete the solution for each type to make sure we're not just faking it
    for i in range(type_count):
        my_agent_list[i].solution = None
        my_agent_list[i].cFunc = None
        my_agent_list[i].time_vary.remove('solution')
        my_agent_list[i].time_vary.remove('cFunc')