Dynare++: interpreting dyn_g_n

Hi,

I am trying to use the results of dynare in R, especially for the
decision rule g(). R can load the resulting matlab file, and I
see all variables, I just need to interpret them.

The manual says that the tensors are folded into line vectors of
dyn_g_n, in a row for each variable, to avoid duplication of
symmetrical derivatives. Could somebody please tell me what the
mapping is for this folding? For example, if n=3, and I need
g_ijk, what is the corresponding index? Pointers to source code
in dynare++, or formulas would be appreciated.

Thanks,

Tamas

I found the answer to my question. In case anybody needs this, the folding algorithm is explained on page 91 (Section 230) of tl.pdf in the Dynare++ documentation.

Best,

Tamas

Dear Tamas,

there are three things needed to be specified: order of columns in the multidimensional index, order of rows, and contents of the tensors.

  1. Order of columns: k-order tensor (dyn_g_k) has its k-dimensional multiindex over a vector of state variables. The state variables vector is a concatenation of predetermined variables (those appearing at t-1) and shocks.

The order of variables is given by dyn_state_vars. The tensor is folded, which means that symmetric derivatives are dropped. This means that if there are m state variables (length of dyn_state_vars), than dyn_g_k has (m+k-1)!/((m-1)!k!) columns. An unfolded version would have m^k columns. In tl.pdf, a section called @<FTensor::getOffsetRecurse code@> gives a description how multiindices are ordered in the folded tensor, and more importantly how to calculate an offset of a given multiindex. Following the example in that section having m=4 and k=3, an offset of multiindex (1,2,2) (starting from zero) will be 14. And if dyn_state_vars=(‘x’,‘y’,‘w’,‘z’) than the derivative with multiindex (1,2,2) is a derivative with respect yw^2 and can be found in the 14-th column.

  1. Order of rows is given by dyn_vars.

  2. The solution is y(t)=g(y(t-1),u(t)), where y is a vector of all endogenous variables, and y(t-1) appearing as an argument of g is restricted only to those variables appearing at time t-1. See point 1 above. A k-dimensional tensor dyn_g_k is equal to k-th derivative of g with respect to stacked vector of y(t-1) and u(t) divided by (k!). So if one wants to recover pure derivatives, he must multiply dyn_g_k with (k!).

One more thing is worth noting: the tensors dyn_g_k were folded by erasing symmetric elements. When the tensor polynomial is evaluated (see tl.pdf sections @<TensorPolynomial::evalTrad code@> and @<TensorPolynomial::evalHorner code@>) the multiple symmetricities of some elements are counted not when derivatives are folded but when powers of x are folded. The later folds row-wise tensor which sums symmetric elements. In Dynare++, the convention is that column-wise folding erases symmetric elements and row-wise folding sums symmetric elements. That’s why the evaluation is correct.

regards,

Ondra K.