コード例 #1
0
sys.path.insert(0, os.path.abspath('../')) #Path to ConsumptionSaving folder
sys.path.insert(0, os.path.abspath('../../'))
sys.path.insert(0, os.path.abspath('../../cstwMPC')) #Path to cstwMPC folder

# Now, bring in what we need from the cstwMPC parameters
import SetupParamsCSTWnew as cstwParams
from HARKutilities import approxUniform

## Import the HARK ConsumerType we want 
## Here, we bring in an agent making a consumption/savings decision every period, subject
## to transitory and permanent income shocks.
from ConsIndShockModel import IndShockConsumerType

# Now initialize a baseline consumer type, using default parameters from infinite horizon cstwMPC
BaselineType = IndShockConsumerType(**cstwParams.init_infinite)
BaselineType.AgentCount = 10000 # Assign the baseline consumer type to have many agents in simulation

####################################################################################################
####################################################################################################
"""
Now, add in ex-ante heterogeneity in consumers' discount factors
"""

# The cstwMPC parameters do not define a discount factor, since there is ex-ante heterogeneity
# in the discount factor.  To prepare to create this ex-ante heterogeneity, first create
# the desired number of consumer types
from copy import deepcopy
num_consumer_types   = 7 # declare the number of types we want
ConsumerTypes = [] # initialize an empty list

for nn in range(num_consumer_types):
コード例 #2
0
    import matplotlib.pyplot as plt
    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.