## Bug in analytical computations of second-order params derivs (d2A and d2Om)

The function `get_first_order_solution_params_deriv.m`

(previously `getH.m`

) does not compute the second-order derivatives `d2A`

and `d2Om`

correctly when using analytical derivatives (kronflag=0|1). If we use numerical derivatives (kronflag=-1|-2) the computations are correct.

To replicate the bug, I looked at the Brock and Mirman model (i.e. RBC model with log utility and full depreciation), where we know analytically the policy functions, i.e. also the Kalman transition matrices of a first-order approximation (A, B and Om) analytically. Hence, using symbolic computations it is possible to compute the true `d2A`

and `d2Om`

and compare the values to dynare.

Here is a mod file to replicate the bug:

and the corresponding matlab file that computes the true objects of the Brock Mirman Model analytically using Matlab's symbolic toolbox:

BrockMirmanTruePolicyAndDerivatives.m

@rattoma is already aware of this bug.