コード例 #1
0
ファイル: ComparisonTests.py プロジェクト: econ-seunghee/HARK
    def setUp(self):

        # Set up and solve infinite type
        import ConsumerParameters as Params

        InfiniteType = IndShockConsumerType(**Params.init_idiosyncratic_shocks)
        InfiniteType.assignParameters(
            LivPrb=[1.],
            DiscFac=0.955,
            PermGroFac=[1.],
            PermShkStd=[0.],
            TempShkStd=[0.],
            T_total=1,
            T_retire=0,
            BoroCnstArt=None,
            UnempPrb=0.,
            cycles=0)  # This is what makes the type infinite horizon

        InfiniteType.updateIncomeProcess()
        InfiniteType.solve()
        InfiniteType.timeFwd()
        InfiniteType.unpackcFunc()

        # Make and solve a perfect foresight consumer type
        PerfectForesightType = deepcopy(InfiniteType)
        PerfectForesightType.solveOnePeriod = solvePerfForesight

        PerfectForesightType.solve()
        PerfectForesightType.unpackcFunc()
        PerfectForesightType.timeFwd()

        self.InfiniteType = InfiniteType
        self.PerfectForesightType = PerfectForesightType
コード例 #2
0
ファイル: Comparison_UnitTests.py プロジェクト: econ-ark/HARK
    def setUp(self):
        """
        Prepare to compare the models by initializing and solving them
        """
        # Set up and solve infinite type
        import ConsumerParameters as Params
        
        InfiniteType = IndShockConsumerType(**Params.init_idiosyncratic_shocks)
        InfiniteType.assignParameters(LivPrb      = [1.],
                                      DiscFac     = 0.955,
                                      PermGroFac  = [1.],
                                      PermShkStd  = [0.],
                                      TempShkStd  = [0.],
                                      T_total = 1, T_retire = 0, BoroCnstArt = None, UnempPrb = 0.,
                                      cycles = 0) # This is what makes the type infinite horizon

        InfiniteType.updateIncomeProcess()        
        InfiniteType.solve()
        InfiniteType.timeFwd()
        InfiniteType.unpackcFunc()


        # Make and solve a perfect foresight consumer type with the same parameters
        PerfectForesightType = deepcopy(InfiniteType)    
        PerfectForesightType.solveOnePeriod = solvePerfForesight
        
        PerfectForesightType.solve()
        PerfectForesightType.unpackcFunc()
        PerfectForesightType.timeFwd()

        self.InfiniteType         = InfiniteType
        self.PerfectForesightType = PerfectForesightType
コード例 #3
0
    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)
    plt.plot(cPermImpulseResponse)

    PermShk = 1
    TranShk = 1.1
    cTranImpulseResponse = AggCons_impulseResponseInd(IndShockExample, PermShk,
                                                      TranShk, 100, 25)
    plt.plot(cTranImpulseResponse)
    print(
        'Impulse response to a one time permanent and transitive shock to income of 10%:'
コード例 #4
0
ファイル: make-scipy-plots.py プロジェクト: fagan2888/PARK-1
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)

# Compare the consumption functions for the perfect foresight and idiosyncratic
# shock types.  Risky income cFunc asymptotically approaches perfect foresight cFunc.
print('Consumption functions for perfect foresight vs idiosyncratic shocks:')
#plotFuncs([PFexample.cFunc[0],IndShockExample.cFunc[0]],IndShockExample.solution[0].mNrmMin,10)

fig, ax1 = plt.subplots()