Replication: Cocco (2005)

This is really nice, I think many people in household finance are working with these models and would find it very useful.

On Cocco (2005): I think without the original code used by the author, it is challenging to replicate. When some time ago we did Chen (2010) (a similar model but without risky assets and in general equilibrium) it was important to look at the Fortran code. For example, the exact spacing used in the Tauchen method was important for the results.

2 Likes

I have just updated the Cocco (2005) codes. Mostly was about converting annual to 5 year. There was also a minor error in keeping track of the ‘stock market participation’ (fixed with an edit to the ReturnFn). Housing is still a bit odd, but if I impose ‘extreme’ behaviour it always gives the right answer (e.g., I changed the utility fn to just being of consumption, and then solution gave housing=0 as without a direct utility from housing, the housing is strictly dominated as an asset by the risky asset)

I think this is as close to the original Cocco (2005) as it is possible to go without knowing what the housing grid should be. That is just so important to the functioning of the model that without it I don’t think we are likely to get any closer to a true replication.

seems weird if this is indeed an average from simulations (especially given the transaction costs)?

The way VFI Toolkit works is to always create the ‘StationaryDist’ by iterating on the agent distribution (taking advantage of the Tan improvement). This is technically not ‘simulation’ as it is not using ‘random number draws’; the ‘panel data’ commands in VFI Toolkit do simulate. The reason is that with modern hardware+software (most importantly GPUs and Tan improvement) the iteration method has a better ‘accuracy-runtime frontier’ than the simulation method. That said, conceptually iteration will give the exact same thing as the average over an infinite number of simulations. [Model statistics are then just calculated directly from the agent distribution.]

2 Likes

I found a bug when running the code with the latest toolkit. There are messages there.

Error: File: CreateReturnFnMatrix_Case2_Disc_Par2e.m Line: 421 Column:
13
 Invalid array indexing.

Error in ValueFnIter_FHorz_RiskyAsset_nod1_e_raw (line 83)
                ReturnMatrix_ze=CreateReturnFnMatrix_Case2_Disc_Par2e(ReturnFn, [n_d3,n_a1], [n_a1,n_a2], special_n_z, special_n_e, d3a1_gridvals, a1a2_gridvals, z_val, e_val, ReturnFnParamsVec);
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in ValueFnIter_Case1_FHorz_RiskyAsset (line 119)
                [VKron, PolicyKron]=ValueFnIter_FHorz_RiskyAsset_nod1_e_raw(n_d2,n_d3,n_a1,n_a2,n_z,vfoptions.n_e,n_u, N_j, d2_grid, d3_grid, a1_grid, a2_grid, z_gridvals_J, vfoptions.e_gridvals_J, u_grid, pi_z_J, vfoptions.pi_e_J, pi_u, ReturnFn, aprimeFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, aprimeFnParamNames, vfoptions);
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in ValueFnIter_Case1_FHorz (line 442)
            [V,Policy]=ValueFnIter_Case1_FHorz_RiskyAsset(n_d,n_a1,n_a2,n_z,vfoptions.n_u, N_j, d_grid, a1_grid, a2_grid, z_gridvals_J, vfoptions.u_grid, pi_z_J, vfoptions.pi_u, ReturnFn, vfoptions.aprimeFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, vfoptions);
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in ValueFnIter_Case1_FHorz_PType (line 145)
        [V_ii, Policy_ii]=ValueFnIter_Case1_FHorz(n_d_temp,n_a_temp,n_z_temp,N_j_temp,d_grid_temp, a_grid_temp, z_grid_temp, pi_z_temp, ReturnFn_temp, Parameters_temp, DiscountFactorParamNames_temp, [], vfoptions_temp);
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in Cocco2005 (line 315)
[V,Policy]=ValueFnIter_Case1_FHorz_PType(n_d,n_a,n_z,N_j,Names_i,d_grid,a_grid,z_grid,pi_z,ReturnFn,Params,DiscountFactorParamNames,vfoptions);
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I checked the earlier script of the ValueFnIter_FHorz_RiskyAsset_nod1_e_raw. There might be a typo error in the 421ish line: “d_gridvals(:,1)(1,1,1)=d_grid(1);”.

elseif l_e==3
    if l_d==1
        if l_a==1 && l_z==1
            d_gridvals(:,1)(1,1,1)=d_grid(1); % Requires special treatment
            ......
3 Likes

Thanks for finding this bug! What you highlighted in bold is certainly not valid Matlab syntax.

1 Like

Fixed. thanks for spotting.

(I expect it would have been introduced when switching the CreateReturnFnMatrix commands over to using d_gridvals instead of d_grid as input; allows more precomputing and makes higher dimensional codes easier to write)

3 Likes

The code file CreateReturnFnMatrix_Case2_Disc_Par2e.m still contains identical syntax errors at lines 249, 590, and 761.

2 Likes

Good spot! I’ve just gone and fixed them now. Thanks!

1 Like