The folder "GLOBAL_EGM_DIST" contains FORTRAN 95 code accompanying the paper 'A generalized endogenous grid method for non-smooth and non-concave problems' by Giulio Fella, g.fella@qmul.ac.uk Copyright 2012 Giulio Fella This version: 14 June 2012 ============================================================================= The following items are provided: 1. The subfolder REPLICATION_EGM containing the code to replicate the simulations of the endogenous grid method algorithm in the paper. 2. The subfolder REPLICATION_VFI1 containing the code to replicate the simulations of the value function iteration algorithm (VFI1 in the paper) which does not use cash at hand as an intermediate variable. 3. The subfolder REPLICATION_VFI2 containing the code to replicate the simulations of the value function iteration algorithm (VFI2 in the paper) which uses cash at hand as an intermediate variable. 4. The file Output.txt in each of the above subfolder reports the parameter used and the simulation for all the Tables in the paper. ============================================================================= This section describes how to use the core of the EGM code. This is also the bulk of the code in the replication code in REPLICATION_EGM. For further information the USER should refer to the extensive comments in the individual modules and subroutines. A search on the string 'USER' in each of the files will return comments to features that have or can be customized by the USER. Assume the following notation. - State vector: (a,s) with 'a' denoting wealth and 's' the vector of all other state variables - c(a,s): consumption function - v(a,s): value function - z(a,s): value of cash at hand in state (a,s) (EXOGENOUS cash at hand nodes) - exp_val(a',s): continuation value = beta*E[v(a',s')|s] - dexp_val(a',s): wealth derivative of exp_val(a',s) GENERAL USE: ------------------------------------------------- 0. The only two procedures the USER needs to modify are MOD_FELICITY.F90 and MOD_COMMON_VAR.F90. 1. The USER needs to enter the felicity function and its first and second derivatives in the module MOD_FELICITY.F90. 2. The USER needs to use 'a_grid' as the name of the array variable for the exogenous asset grid. The variable is declared global in the module MOD_COMMON_VAR.F90. Its size 'len_a_grid' needs to be entered by the USER in the module MOD_COMMON_VAR.F90. 3. Given USER-supplied guesses for the continuation value function exp_val(a',s) and its wealth derivative dexp_val(a',s), for each s on the appropriate grid call first SUB_GLOBALEGM and then SUB_EGMINTERP to obtain the consumption and value functions c(a,s) and v(a,s) in state s, for all values of a on the wealth grid a_grid. 4. The USER can select whether to use the exogenous or the endogenous grid points in the *simulation* by setting the flag EG_FLAG in MOD_COMMON_VAR.f90 to 0 (exogenous grid) or 1 (endogenous grid). The simulations in the paper were run with EG_FLAG=0. USE of the individual subroutines (in order of importance for the USER) ------------------------------------------------- 1. SUB_GLOBALEGM in the file SUB_GLOBALEGM.F90 For given s on the relevant grid, it takes as inputs the functions of future wealth - for all a' on the grid a_grid - exp_val(a',s) and exp_dval(a',s) and returns the consumption and value functions and the associated endogenous grid points for cash at hand. Dependencies: - calls the subroutine SUB_NEWTON (Newton non-linear solver) in module MOD_SOLVER.F90 to find zeros of various functions. - calls the subroutine QSORT_C (Newton non-linear solver) in module MOD_QSORT.F90 to sort the zeros of the Euler equation in increasing order of cash at hand. 2. SUB_EGMINTERP in the file SUB_EGMINTERP.F90 For given s on the relevant grid, it interpolates - on the exogenous grid points for cash at hand z(a,s) - the consumption and value functions returned by sub_globalegm and outputs the consumption and value fns c(a,s) and v(a,s). Dependencies: - calls the subroutine SUB_INT_NODE in module MOD_INT_NODE.F90 to determine the index of the closest interpolating node to the RIGHT of the interpolation point. 3. MOD_FELICITY.F90 It contains the felicity function (FEL) and its first (DFEL) and second (D2FEL) derivatives. The three function need to be amended appropriately by the USER. Each function has a scalar version (e.g. fel_sc) and an array-valued version (e.g fel_ar). The function is the same in the two versions, but the user needs to make sure to amend both. 4. MOD_FCN.F90 It uses the functions in mod_felicity to construct various subroutines used by the non-linear solver SUB_NEWTON. 5. SUB_INT_NODE in module MOD_INT_NODE.f90 It returns the index of the closest interpolating node to the RIGHT of the interpolation point. It contains both a scalar (sub_int_node_sc) and an array version (sub_int_node_ar). The array version assumes the set of interpolating nodes are ordered by ascissa and exploits this to speed up the code. 6. MOD_SOLVER.F90 Contains the subroutines SUB_NEWTON and SUB_HYBRID_NB. These iare a slightly modified Newton solver that ensures that iterates do not fall below a USER-specified lower bound and a hybrid Newton-bisection subroutine in case SUB_NEWTON exceeds a max number of iterations. 7. MOD_COMMON_VAR.F90 Declares global variables used by the algorithm. 8. MOD_TYPES.F90 Declares global parameters associated with the precision of real variables. ============================================================================= This section details the extra code in the three replication folders. 1. MAIN.F90 Constructs the various grids, sets the guess for the value function equal to the felicity function fel and calls the subroutine SUB_VALUEITER (for EGM, or for discretized VFI) or SUB_VALUEITER2 (for linearly interpolated VFI). Calls the subroutine SUB_DYNEULER. 2. SUB_VALUEITER.F90. Iterates on the value function and returns converged policy and value functions. The one in the REPLICATION_EGM folder calls the subroutine SUB_GLOBALEGM. 3. SUB_VALUITER2.f90 Iterates on the value function and returns converged policy and value functions. Uses linearly interpolated VFI. 4. SUB_EULERERRORS.F90 Computes Euler errors at grid points which the borrowing constraint is not binding. 5. SUB_SIMULDYNEULER.F90 Calls the subroutine SUB_POLOFFGRID and computes and prints maximum and average Euler error along a simulated path. 6. SUB_POLOFFGRID.F90 Computes interpolated policy functions using exogenous interpolating nodes. 7. SUB_SIMULDYNEULER_EG.F90 Calls the subroutine SUB_POLOFFGRID_EG and computes and prints maximum and average Euler error along a simulated path. 8. SUB_POLOFFGRID_EG.F90 Computes interpolated policy functions using endogenous interpolating nodes. 9. SUB_RNUMDERIV.F90 Computes derivative of a function at given nodes using finite differences. 10. SUB_TAUCHEN.F90 Computes discrete approximation for the income process, using the method in Tauchen (1986). 11. FUN_CUM_NORMAL.F90 Returns the ascissa of the normal cumulative density at a percentile. 10. SUB_GRID.F90 Generates various types of grids between uniform and triple explonential. 12. MOD_INTERFACE.F90 Interface for some functions and subroutines.