コード例 #1
0
def perturbParameterToGetcPlotList(base_dictionary,
                                   param_name,
                                   param_min,
                                   param_max,
                                   N=20,
                                   time_vary=False):
    param_vec = np.linspace(
        param_min, param_max, num=N, endpoint=True
    )  # vector of alternative values of the parameter to examine
    thisConsumer = IndShockConsumerType(
        **my_dictionary)  # create an instance of the consumer type
    thisConsumer.cycles = 0  # Make this type have an infinite horizon
    x = np.linspace(
        mMinVal, mMaxVal, xPoints, endpoint=True
    )  # Define a vector of x values that span the range from the minimum to the maximum values of m

    for j in range(
            N):  # loop from the first to the last values of the parameter
        if time_vary:  # Some parameters are time-varying; others are not
            setattr(thisConsumer, param_name, [param_vec[j]])
        else:
            setattr(thisConsumer, param_name, param_vec[j])
        thisConsumer.update(
        )  # set up the preliminaries required to solve the problem
        thisConsumer.solve()  # solve the problem
        y = thisConsumer.solution[0].cFunc(
            x
        )  # Get the values of the consumption function at the points in the vector of x points
        pylab.plot(
            x, y, label=str(round(param_vec[j], 3))
        )  # plot it and generate a label indicating the rounded value of the parameter
        pylab.legend(loc='upper right')  # put the legend in the upper right
    return pylab  # return the figure
コード例 #2
0
## There is one more parameter value we need to change.  This one is more complicated than the rest.
## We could solve the problem for a consumer with an infinite horizon of periods that (ex-ante)
## are all identical.  We could also solve the problem for a consumer with a fininite lifecycle,
## or for a consumer who faces an infinite horizon of periods that cycle (e.g., a ski instructor
## facing an infinite series of winters, with lots of income, and summers, with very little income.)
## The way to differentiate is through the "cycles" attribute, which indicates how often the
## sequence of periods needs to be solved.  The default value is 1, for a consumer with a finite
## lifecycle that is only experienced 1 time.  A consumer who lived that life twice in a row, and
## then died, would have cycles = 2.  But neither is what we want.  Here, we need to set cycles = 0,
## to tell HARK that we are solving the model for an infinite horizon consumer.


## Note that another complication with the cycles attribute is that it does not come from
## Params.init_idiosyncratic_shocks.  Instead it is a keyword argument to the  __init__() method of
## IndShockConsumerType.
BaselineExample.cycles = 0


####################################################################################################
####################################################################################################

"""
Now, create another consumer to compare the BaselineExample to.
"""
# The easiest way to begin creating the comparison example is to just copy the baseline example.
# We can change the parameters we want to change later.
from copy import deepcopy

XtraCreditExample = deepcopy(BaselineExample)

コード例 #3
0
    # Remove TimeBefore periods
    cAggImpulseResponse = cAggImpulseResponse[TimeBefore:]

    return cAggImpulseResponse


###############################################################################

if __name__ == '__main__':
    import ConsumerParameters as Params
    from time import clock
    mystr = lambda number: "{:.4f}".format(number)

    # Make and solve an example consumer with idiosyncratic income shocks
    IndShockExample = IndShockConsumerType(**Params.init_idiosyncratic_shocks)
    IndShockExample.cycles = 0  # Make this type have an infinite horizon
    IndShockExample.DiePrb = 1 - IndShockExample.LivPrb[
        0]  # Not sure why this is not already in the object

    start_time = clock()
    IndShockExample.solve()
    end_time = clock()
    print('Solving a consumer with idiosyncratic shocks took ' +
          mystr(end_time - start_time) + ' seconds.')
    IndShockExample.unpackcFunc()
    IndShockExample.timeFwd()

    PermShk = 1.1
    TranShk = 1
    cPermImpulseResponse = AggCons_impulseResponseInd(IndShockExample, PermShk,
                                                      TranShk, 100, 25)
コード例 #4
0
## There is one more parameter value we need to change.  This one is more complicated than the rest.
## We could solve the problem for a consumer with an infinite horizon of periods that (ex-ante)
## are all identical.  We could also solve the problem for a consumer with a fininite lifecycle,
## or for a consumer who faces an infinite horizon of periods that cycle (e.g., a ski instructor
## facing an infinite series of winters, with lots of income, and summers, with very little income.)
## The way to differentiate is through the "cycles" attribute, which indicates how often the
## sequence of periods needs to be solved.  The default value is 1, for a consumer with a finite
## lifecycle that is only experienced 1 time.  A consumer who lived that life twice in a row, and
## then died, would have cycles = 2.  But neither is what we want.  Here, we need to set cycles = 0,
## to tell HARK that we are solving the model for an infinite horizon consumer.


## Note that another complication with the cycles attribute is that it does not come from
## Params.init_idiosyncratic_shocks.  Instead it is a keyword argument to the  __init__() method of
## IndShockConsumerType.
BaselineExample.cycles      = 0


####################################################################################################
####################################################################################################

"""
Now, create another consumer to compare the BaselineExample to.
"""
# The easiest way to begin creating the comparison example is to just copy the baseline example.
# We can change the parameters we want to change later.
from copy import deepcopy
XtraCreditExample = deepcopy(BaselineExample)


# Now, change whatever parameters we want.
コード例 #5
0
ファイル: make-scipy-plots.py プロジェクト: fagan2888/PARK-1
print('Solving a perfect foresight consumer took ' +
      mystr(end_time - start_time) + ' seconds.')
PFexample.unpackcFunc()
PFexample.timeFwd()

# Plot the perfect foresight consumption function
print('Linear consumption function:')
mMin = PFexample.solution[0].mNrmMin

#plotFuncs(PFexample.cFunc[0],mMin,mMin+10)

###############################################################################

# Make and solve an example consumer with idiosyncratic income shocks
IndShockExample = IndShockConsumerType(**Params.init_idiosyncratic_shocks)
IndShockExample.cycles = 0  # Make this type have an infinite horizon

start_time = clock()
IndShockExample.solve()
end_time = clock()
print('Solving a consumer with idiosyncratic shocks took ' +
      mystr(end_time - start_time) + ' seconds.')
IndShockExample.unpackcFunc()
IndShockExample.timeFwd()

# Plot the consumption function and MPC for the infinite horizon consumer
#print('Concave consumption function:')
#plotFuncs(IndShockExample.cFunc[0],IndShockExample.solution[0].mNrmMin,5)
#print('Marginal consumption function:')
#plotFuncsDer(IndShockExample.cFunc[0],IndShockExample.solution[0].mNrmMin,5)