Page 1 of 1
manipulating the decision rules
Posted:
Sun Oct 17, 2010 2:40 pm
by ian_db
Hi,
I'm trying to use the decision rules to calculate some asset prices. That is, I want to integrate over the shocks conditional on today's values of the state variables (I don't want to approximate the asset prices around the nonstochastic steady state as that doesn't seem to work very well).
Is there a function somewhere inside dynare that will help me do this automatically? I'm a bit worried about my ability to figure out how to unfold the big matrices for the third-order decision rules without getting something wrong.
Thanks,
Ian
Re: manipulating the decision rules
Posted:
Mon Nov 22, 2010 11:41 am
by SébastienVillemot
You can either look at the reference manual in the section about “stoch_simul”: the matrices for decision rules at 1st, 2nd and 3rd order are explained there.
You can also look at the code in “simult_.m” which uses the decision rules to simulate the model; note that for 3rd order, the actual code is contained in a DLL (called dynare_simul_.m) so you have to look at the C++ source code which is not trivial to understand.
Best,
Re: manipulating the decision rules
Posted:
Thu Dec 09, 2010 1:45 pm
by amfasolo
Hi everyone,
I'm also trying to unfold the G2 and G3 matrices, but I couldn't find the sources of the C code of "Dynare_simul" to check what is going on. However, following the instructions in Dynare's manual, I wrote a small piece of Matlab code to rewrite the G2 matrix generated in Dynare in the "unfolded" way. I'm attaching the file with the matlab function, where the only two arguments necessary to execute it are the G2 matrix and the number of states+shocks of the model.
Is it possible for anyone to check if the output matrix is written in the right way? Or, at least, show the path where we can find the source of the C code that runs the simulations for order=3?
Thanks in advance!
Angelo
Re: manipulating the decision rules
Posted:
Tue Dec 14, 2010 1:54 pm
by ian_db
I've attached some code that I wrote to unfold the decision rules. It takes as input the current values of the state variables and shocks, and outputs the endogenous variables. Sorry it's not terribly extensively commented.
Thanks, by the way, for the help before.
Re: manipulating the decision rules
Posted:
Tue Dec 14, 2010 4:19 pm
by amfasolo
Great piece of code, Ian!!!
With the structure you wrote in the code, it should be easy to generalize to approximations of order higher than 3, right? Of course, as long as the n-th order approximation of the model is written as:
Yt = G1 + G2*zt + G2*(zt k zt) + G3*(zt k zt k zt) + G4*(zt k zt k zt k zt) + ... + Gn*(zt k zt k zt k zt k... zt)
Best,
Angelo
Re: manipulating the decision rules
Posted:
Fri Apr 13, 2012 10:50 am
by chico
Dear all,
I'm having the same problem... did you ever manage to unfold the G3 matrix?
If you did I would much appreciate if you could share it with me.
Thanks in advance,
chico
Re: manipulating the decision rules
Posted:
Mon Apr 16, 2012 1:08 am
by amfasolo
Hi Chico,
Following is my version of the code to unfold G3 matrix. You need also the file I posted before with the code to unfold G2 matrix in order to make it run properly.
Comments, suggestions, checks are always welcome.
Re: manipulating the decision rules
Posted:
Wed Nov 18, 2015 5:32 pm
by SamuelHurtado
Hi
I'm also using Dynare to calculate a third-order approximation that I then use outside Dynare, which means that I have to unfold the oo_.dr.g_2 and oo_.dr.g_3 matrices.
The codes posted here were not working for me: I got an "index out of bounds" error when the G3 function calls the G2 function. I tried to fix them but it wasn't easy, and finally I ended up writing my own thing. It's A LOT simpler than what was posted before, so there's much less room for bugs or typos. Still, don't underestimate my ability to screw things up: check before use. It's really simple, it will take you just two minutes.
Enjoy!
Re: manipulating the decision rules
Posted:
Wed Nov 18, 2015 5:32 pm
by SamuelHurtado
Can't upload two files to a single post, so here's the unfolder for G3
Re: manipulating the decision rules
Posted:
Wed Nov 18, 2015 6:57 pm
by jpfeifer