コード例 #1
0
def makeNonFarmerHist(stdPerm, stdTran, numAgents, numPeriods):
    NonFarmerParams = {
        'BoroCnstArt': 0.0,
        'CRRA': np.inf,
        'CubicBool': True,
        'DiscFac': 0.5,
        'IncUnemp': 0.0,
        'IncUnempRet': 0.0,
        'LivPrb': [0.98],
        'Nagents': 100,
        'PermGroFac': [1.01],
        'PermShkCount': 20,
        'PermShkStd': [stdPerm],
        'Rfree': 1.0,
        'T_retire': 0,
        'T_total': 1,
        'TranShkCount': numAgents,
        'TranShkStd': [stdTran],
        'UnempPrb': 0.0,
        'UnempPrbRet': 0.00,
        'aXtraCount': 12,
        'aXtraExtra': [None],
        'aXtraMax': 20,
        'aXtraMin': 0.001,
        'aXtraNestFac': 3,
        'tax_rate': 0.0,
        'vFuncBool': False
    }
    PerfForNonFarmer = PerfForesightConsumerType(**NonFarmerParams)
    PerfForNonFarmer.solve()
    NonFarmer = IndShockConsumerType(**NonFarmerParams)
    NonFarmer.solution = copy.deepcopy(PerfForNonFarmer.solution)
    NonFarmer.addToTimeVary('solution')
    NonFarmer.sim_periods = numPeriods
    NonFarmer.initializeSim(sim_prds=NonFarmer.sim_periods)
    NonFarmer.makeIncShkHist()
    NonFarmer.simConsHistory()
    NonFarmer.IncHist = np.multiply(NonFarmer.PermShkHist,
                                    NonFarmer.TranShkHist)
    NonFarmer.IncHist = np.reshape(
        NonFarmer.IncHist, (NonFarmer.Nagents * NonFarmer.sim_periods, 1))
    NonFarmer.cHist = np.reshape(
        NonFarmer.cHist, (NonFarmer.Nagents * NonFarmer.sim_periods, 1))
    NonFarmer.IncHist = list(itertools.chain.from_iterable(NonFarmer.IncHist))
    NonFarmer.cHist = list(itertools.chain.from_iterable(NonFarmer.cHist))
    return (NonFarmer.IncHist, NonFarmer.cHist)
コード例 #2
0
    from copy import deepcopy
    from time import clock
    from HARK.parallel import multiThreadCommands, multiThreadCommandsFake

    # Set up a baseline IndShockConsumerType, which will be replicated.
    # In this case, we use a completely arbitrary 10 period lifecycle.
    TestType = IndShockConsumerType(**Params.init_lifecycle)
    TestType.TestVar = np.empty(
        TestType.AgentCount
    )  # This is for making an empty buffer for diagnostics
    TestType.CubicBool = True  # Cubic interpolation must be on, because that's what's used in OpenCL version
    T_sim = 10  # Choose simulation length
    AgentCount = 100  # Chose number of agents in each type
    TestType.T_sim = T_sim  # Choose number of periods to simulate
    TestType.AgentCount = AgentCount
    TestType.initializeSim()  # Set up some objects for simulation

    # Make a list with many copies of the baseline agent type, each with a different CRRA.
    TypeCount = 100
    CRRAmin = 1.0
    CRRAmax = 5.0
    CRRAset = np.linspace(CRRAmin, CRRAmax, TypeCount)
    TypeList = []
    for j in range(TypeCount):
        NewType = deepcopy(TestType)
        NewType(CRRA=CRRAset[j])
        TypeList.append(NewType)

    # Construct an instance of IndShockConsumerTypesOpenCL by passing the type list to the constructor.
    # Note the plural in the class name; each instance of this class represents *several* types.
    TestOpenCL = IndShockConsumerTypesOpenCL(TypeList)