Ejemplo n.º 1
0
    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],
                            "aXtraNestFac":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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
                            "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)
    print('Difference between the (employed) consumption functions:')
    plotFuncs(diffFunc,0,m_upper)
           
Ejemplo n.º 4
0
                         "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)
 print('Difference between the (employed) consumption functions:')
 plotFuncs(diffFunc,0,m_upper)