Exemplo 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()
Exemplo n.º 2
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()
Exemplo n.º 3
0
import ConsIndShockModel as Model         # Consumption-saving model with idiosyncratic shocks
from HARKutilities import plotFuncs, plotFuncsDer # 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.IndShockConsumerType(**Params.init_idiosyncratic_shocks)
    BasicType.cycles = 0
    BasicType(aXtraMax  = 100, aXtraCount = 64)
    BasicType(vFuncBool = False, CubicBool = True)
    BasicType.updateAssetsGrid()
    BasicType.timeFwd()    
   
    # Solve the basic type and plot the results, to make sure things are working
    start_time = clock()
    BasicType.solve()
    end_time = clock()
    print('Solving the basic consumer took ' + mystr(end_time-start_time) + ' seconds.')
    BasicType.unpackcFunc()
    print('Consumption function:')
    plotFuncs(BasicType.cFunc[0],0,5)    # plot consumption
    print('Marginal consumption function:')
Exemplo n.º 4
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
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,
    seed=Params.seed)  # Draw initial assets for each consumer