コード例 #1
0
ファイル: ComparisonTests.py プロジェクト: econ-seunghee/HARK
    def setUp(self):
        # Set up and solve TBS
        base_primitives = {
            'UnempPrb': .015,
            'DiscFac': 0.9,
            'Rfree': 1.1,
            'PermGroFac': 1.05,
            'CRRA': .95
        }

        TBSType = TractableConsumerType(**base_primitives)
        TBSType.solve()

        # Set up and solve Markov
        MrkvArray = np.array(
            [[1.0 - base_primitives['UnempPrb'], base_primitives['UnempPrb']],
             [0.0, 1.0]])
        Markov_primitives = {
            "CRRA":
            base_primitives['CRRA'],
            "Rfree":
            np.array(2 * [base_primitives['Rfree']]),
            "PermGroFac": [
                np.array(2 * [
                    base_primitives['PermGroFac'] /
                    (1.0 - base_primitives['UnempPrb'])
                ])
            ],
            "BoroCnstArt":
            None,
            "PermShkStd": [0.0],
            "PermShkCount":
            1,
            "TranShkStd": [0.0],
            "TranShkCount":
            1,
            "T_total":
            1,
            "UnempPrb":
            0.0,
            "UnempPrbRet":
            0.0,
            "T_retire":
            0,
            "IncUnemp":
            0.0,
            "IncUnempRet":
            0.0,
            "aXtraMin":
            0.001,
            "aXtraMax":
            TBSType.mUpperBnd,
            "aXtraCount":
            48,
            "aXtraExtra": [None],
            "exp_nest":
            3,
            "LivPrb": [1.0],
            "DiscFac":
            base_primitives['DiscFac'],
            'Nagents':
            1,
            'psi_seed':
            0,
            'xi_seed':
            0,
            'unemp_seed':
            0,
            'tax_rate':
            0.0,
            'vFuncBool':
            False,
            'CubicBool':
            True,
            'MrkvArray':
            MrkvArray
        }

        MarkovType = MarkovConsumerType(**Markov_primitives)
        MarkovType.cycles = 0
        employed_income_dist = [np.ones(1), np.ones(1), np.ones(1)]
        unemployed_income_dist = [np.ones(1), np.ones(1), np.zeros(1)]
        MarkovType.IncomeDstn = [[
            employed_income_dist, unemployed_income_dist
        ]]

        MarkovType.solve()
        MarkovType.unpackcFunc()

        self.TBSType = TBSType
        self.MarkovType = MarkovType
コード例 #2
0
                         "IncUnemp":0.0,       # Income when unemployed (irrelevant)
                         "IncUnempRet":0.0,    # Income when unemployed and retired (irrelevant)
                         "aXtraMin":0.001,     # Minimum value of assets above minimum in grid
                         "aXtraMax":ExampleType.mUpperBnd, # Maximum value of assets above minimum in grid
                         "aXtraCount":48,      # Number of points in assets grid
                         "aXtraExtra":[None],  # Additional points to include in assets grid
                         "aXtraNestFac":3,     # Degree of exponential nesting when constructing assets grid
                         "LivPrb":[np.array([1.0,1.0])], # Survival probability
                         "DiscFac":base_primitives['DiscFac'], # Intertemporal discount factor
                         'AgentCount':1,       # Number of agents in a simulation (irrelevant)
                         'tax_rate':0.0,       # Tax rate on labor income (irrelevant)
                         'vFuncBool':False,    # Whether to calculate the value function
                         'CubicBool':True,     # Whether to use cubic splines (False --> linear splines)
                         'MrkvArray':[MrkvArray] # State transition probabilities
                         }
 MarkovType = MarkovConsumerType(**init_consumer_objects)   # Make a basic consumer type
 employed_income_dist = [np.ones(1),np.ones(1),np.ones(1)]    # Income distribution when employed
 unemployed_income_dist = [np.ones(1),np.ones(1),np.zeros(1)] # Income distribution when permanently unemployed
 MarkovType.IncomeDstn = [[employed_income_dist,unemployed_income_dist]]  # set the income distribution in each state
 MarkovType.cycles = 0
 
 # Solve the "Markov TBS" model
 t_start = clock()
 MarkovType.solve()
 t_end = clock()
 MarkovType.unpackcFunc()
 
 print('Solving the same model "the long way" took ' + str(t_end-t_start) + ' seconds.')
 #plotFuncs([ExampleType.solution[0].cFunc,ExampleType.solution[0].cFunc_U],0,m_upper)
 plotFuncs(MarkovType.cFunc[0],0,m_upper)
 diffFunc = lambda m : ExampleType.solution[0].cFunc(m) - MarkovType.cFunc[0][0](m)
コード例 #3
0
ファイル: Chinese_Growth.py プロジェクト: mnwhite/HARK
# One other parameter to change: the number of agents in simulation
# We want to increase this, because later on when we vastly increase the variance of the permanent
# income shock, things get wonky.
# It is important to note that we need to change this value here, before we have used the parameters
# to initialize the MarkovConsumerType.  This is because this parameter is used during initialization.
# Other parameters that are not used during initialization can also be assigned here,
# by changing the appropriate value in the init_China_parameters_dictionary; however,
# they can also be changed later, by altering the appropriate attribute of the initialized
# MarkovConsumerType.
init_China_parameters['AgentCount'] = 10000

### Import and initialize 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, AND a Markov shock
from ConsMarkovModel import MarkovConsumerType
ChinaExample = MarkovConsumerType(**init_China_parameters)

# Currently, Markov states can differ in their interest factor, permanent growth factor,
# survival probability, and income distribution.  Each of these needs to be specifically set.
# Do that here, except income distribution.  That will be done later, because we want to examine
# the effects of different income distributions.

ChinaExample.assignParameters(
    PermGroFac=[
        np.array([1., 1.06**(.25)])
    ],  #needs to be a list, with 0th element of shape of shape (StateCount,)
    Rfree=np.array(StateCount *
                   [init_China_parameters['Rfree']
                    ]),  #need to be an array, of shape (StateCount,)
    LivPrb=[
        np.array(StateCount * [init_China_parameters['LivPrb']][0])
コード例 #4
0
ファイル: ComparisonTests.py プロジェクト: ganong123/HARK
        MarkovType.solution_terminal.vPPfunc = 2*[MarkovType.solution_terminal.vPPfunc]
        MarkovType.solution_terminal.mNrmMin = 2*[MarkovType.solution_terminal.mNrmMin]
        MarkovType.solution_terminal.MPCmax  = np.array(2*[MarkovType.solution_terminal.MPCmax])
        MarkovType.IncomeDstn = [[employed_income_dist,unemployed_income_dist]]
        MarkovType.MrkvArray = MrkvArray
        MarkovType.time_inv.append('MrkvArray')
        MarkovType.solveOnePeriod = solveConsumptionSavingMarkov
        MarkovType.cycles = 0
        MarkovType.solve()
        MarkovType.unpack_cFunc()
=======
                            'CubicBool':True,
                            'MrkvArray':MrkvArray
                            }
                
        MarkovType = MarkovConsumerType(**Markov_primitives)                           
        MarkovType.cycles = 0
        employed_income_dist                 = [np.ones(1),np.ones(1),np.ones(1)]
        unemployed_income_dist               = [np.ones(1),np.ones(1),np.zeros(1)]
        MarkovType.IncomeDstn = [[employed_income_dist,unemployed_income_dist]]
        
        MarkovType.solve()
        MarkovType.unpackcFunc()
>>>>>>> eeb37f24755d0c683c9d9efbe5e7447425c98b86
 
        self.TBSType    = TBSType
        self.MarkovType = MarkovType

    def test_consumption(self):
        # Now compare the consumption functions and make sure they are "close"