Esempio n. 1
0
 def update(self):
     '''
     Update the income process, the assets grid, and the terminal solution.
     
     Parameters
     ----------
     none
         
     Returns
     -------
     none
     '''
     orig_flow = self.time_flow        
     if self.cycles == 0: # hacky fix for labor supply l_bar
         self.updateIncomeProcessAlt()
     else:
         self.updateIncomeProcess()
     self.updateAssetsGrid()
     self.updateSolutionTerminal()
     self.timeFwd()
     self.resetRNG()
     if self.cycles > 0:
         self.IncomeDstn = Model.applyFlatIncomeTax(self.IncomeDstn,
                                              tax_rate=self.tax_rate,
                                              T_retire=self.T_retire,
                                              unemployed_indices=range(0,(self.TranShkCount+1)*
                                              self.PermShkCount,self.TranShkCount+1))          
     self.makeIncShkHist()
     if not orig_flow:
         self.timeRev()
Esempio n. 2
0
 def update(self):
     '''
     Update the income process and the assets grid.
     '''
     orig_flow = self.time_flow
     self.updateIncomeProcess()
     self.updateAssetsGrid()
     if self.cycles > 0:
         self.income_distrib = Model.applyFlatIncomeTax(
             self.income_distrib,
             tax_rate=self.tax_rate,
             T_retire=self.T_retire,
             unemployed_indices=range(0, (self.xi_N + 1) * self.psi_N,
                                      self.xi_N + 1))
         scriptR_shocks, xi_shocks = Model.generateIncomeShockHistoryLognormalUnemployment(
             self)
         self.addIncomeShockPaths(scriptR_shocks, xi_shocks)
     else:
         self.timeRev()
         scriptR_shocks, xi_shocks = Model.generateIncomeShockHistoryInfiniteSimple(
             self)
         self.addIncomeShockPaths(scriptR_shocks, xi_shocks)
     if orig_flow:
         self.timeFwd()
Esempio n. 3
0
 def simulateMPC(self):
     original_time = self.time_flow
     self.timeFwd()
     t_first = 0
     t_last = self.sim_periods
     if self.cycles > 0:
         cFuncs = self.cFunc[t_first:t_last]
     else:
         cFuncs = t_last * self.cFunc
     simulated_kappa_matrix = Model.simulateMPChistory(
         cFuncs, self.w0, self.perm_shocks[t_first:t_last],
         self.temp_shocks[t_first:t_last])
     if not original_time:
         self.timeRev()
     self.kappa_history = simulated_kappa_matrix
Esempio n. 4
0
 def update(self):
     '''
     Update the income process and the assets grid.
     '''
     orig_flow = self.time_flow        
     if self.cycles == 0: # hacky fix for labor supply l_bar
         self.updateIncomeProcessAlt()
     else:
         self.updateIncomeProcess()
     self.updateAssetsGrid()
     self.updateSolutionTerminal()
     self.timeFwd()
     if self.cycles > 0:
         self.income_distrib = Model.applyFlatIncomeTax(self.income_distrib,
                                              tax_rate=self.tax_rate,
                                              T_retire=self.T_retire,
                                              unemployed_indices=range(0,(self.xi_N+1)*self.psi_N,self.xi_N+1))
         scriptR_shocks, xi_shocks = Model.generateIncomeShockHistoryLognormalUnemployment(self)    
         self.addIncomeShockPaths(scriptR_shocks,xi_shocks)   
     else:
         scriptR_shocks, xi_shocks = Model.generateIncomeShockHistoryInfiniteSimple(self)
         self.addIncomeShockPaths(scriptR_shocks,xi_shocks)
     if not orig_flow:
         self.timeRev()
Esempio n. 5
0
from HARKestimation import minimizeNelderMead, bootstrapSampleFromData
import numpy as np
import pylab
from time import time

# Set booleans to determine which tasks should be done
estimate_model = True
compute_standard_errors = False
make_contour_plot = True

#=====================================================
# Define objects and functions used for the estimation
#=====================================================

# Make a lifecycle consumer to be used for estimation, including simulated shocks (plus an initial distribution of wealth)
EstimationAgent = Model.ConsumerType(**Params.init_consumer_objects)
EstimationAgent(sim_periods=EstimationAgent.T_total + 1)
EstimationAgent.makeIncShkHist()
EstimationAgent.a_init = drawDiscrete(
    P=Params.initial_wealth_income_ratio_probs,
    X=Params.initial_wealth_income_ratio_vals,
    N=Params.num_agents,
    seed=Params.seed)


# Define the objective function for the estimation
def smmObjectiveFxn(DiscFacAdj,
                    CRRA,
                    agent=EstimationAgent,
                    DiscFacAdj_bound=Params.DiscFacAdj_bound,
                    CRRA_bound=Params.CRRA_bound,
Esempio n. 6
0
import sys
from HARKutilities import plotFunc, plotFuncDer, plotFuncs  # Basic plotting tools
from time import clock  # Timing utility
from copy import deepcopy  # "Deep" copying for complex objects
from HARKparallel import multiThreadCommandsFake, multiThreadCommands  # Parallel processing
mystr = lambda number: "{:.4f}".format(number)  # Format numbers as strings
import numpy as np  # Numeric Python

if __name__ == '__main__':  # Parallel calls *must* be inside a call to __main__
    type_count = 32  # Number of values of CRRA to solve

    # Make the basic type that we'll use as a template.
    # The basic type has an artificially dense assets grid, as the problem to be
    # solved must be sufficiently large for multithreading to be faster than
    # single-threading (looping), due to overhead.
    BasicType = Model.ConsumerType(**Params.init_consumer_objects)
    BasicType.aXtraMax = 100
    BasicType.aXtraCount = 64
    BasicType.updateAssetsGrid()
    BasicType.timeFwd()
    BasicType.assignParameters(
        LivPrb=[0.98], DiscFac=[0.96], PermGroFac=[1.01],
        cycles=0)  # This is what makes the type infinite horizon
    BasicType(vFuncBool=False, cubicBool=True)
    BasicType.IncomeDstn = [
        BasicType.IncomeDstn[0]
    ]  # A "one period" infinite horizon model, so only need one period of income distributions

    # Solve the basic type and plot the results, to make sure things are working
    start_time = clock()
    BasicType.solve()
Esempio n. 7
0
from HARKestimation import minimizeNelderMead, bootstrapSampleFromData # Estimation methods
import numpy as np                              # Numeric Python
import pylab                                    # Python reproductions of some Matlab functions
from time import time                           # Timing utility

# Set booleans to determine which tasks should be done
estimate_model = True             # Whether to estimate the model
compute_standard_errors = False   # Whether to get standard errors via bootstrap
make_contour_plot = False         # Whether to make a contour map of the objective function

#=====================================================
# Define objects and functions used for the estimation
#=====================================================

# Make a lifecycle consumer to be used for estimation, including simulated shocks (plus an initial distribution of wealth)
EstimationAgent = Model.IndShockConsumerType(**Params.init_consumer_objects) # Make a ConsumerType for estimation
<<<<<<< HEAD
EstimationAgent(sim_periods = EstimationAgent.T_total+1)             # Set the number of periods to simulate
EstimationAgent.makeIncShkHist()                                     # Make a simulated history of income shocks for many consumers
EstimationAgent.a_init = drawDiscrete(P=Params.initial_wealth_income_ratio_probs,
                                      X=Params.initial_wealth_income_ratio_vals,
                                      N=Params.num_agents,
=======
EstimationAgent.time_inv.remove('DiscFac')                           # This estimation uses age-varying discount factors as
EstimationAgent.time_vary.append('DiscFac')                          # estimated by Cagetti (2003), so switch from time_inv to time_vary
EstimationAgent(sim_periods = EstimationAgent.T_total+1)             # Set the number of periods to simulate
EstimationAgent.makeIncShkHist()                                     # Make a simulated history of income shocks for many consumers
EstimationAgent.a_init = drawDiscrete(N=Params.num_agents,
                                      P=Params.initial_wealth_income_ratio_probs,
                                      X=Params.initial_wealth_income_ratio_vals,                                      
>>>>>>> eeb37f24755d0c683c9d9efbe5e7447425c98b86
Esempio n. 8
0
from time import time

# Set booleans to determine which tasks should be done
estimate_model = True
compute_standard_errors = False
make_contour_plot = False

#=====================================================
# Define objects and functions used for the estimation
#=====================================================

# Make a lifecycle consumer to be used for estimation, including simulated shocks
EstimationAgent = Model.ConsumerType(**Params.init_consumer_objects)

# Make histories of permanent and transitory shocks, plus an initial distribution of wealth
scriptR_shocks, xi_shocks = Model.generateIncomeShockHistoryLognormalUnemployment(EstimationAgent)
w0_vector = generateDiscreteDraws(P=Params.initial_wealth_income_ratio_probs,
                                         X=Params.initial_wealth_income_ratio_vals,
                                         N=Params.num_agents,
                                         seed=Params.seed)
EstimationAgent.addIncomeShockPaths(scriptR_shocks,xi_shocks)

# Define the objective function for the estimation
def smmObjectiveFxn(beth, rho,
                     agent = EstimationAgent,
                     beth_bound = Params.beth_bound,
                     rho_bound = Params.rho_bound,
                     empirical_data = Data.w_to_y_data,
                     empirical_weights = Data.empirical_weights,
                     empirical_groups = Data.empirical_groups,
                     initial_wealth = w0_vector,