manipulating the decision rules

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

manipulating the decision rules

Postby ian_db » Sun Oct 17, 2010 2:40 pm

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
ian_db
 
Posts: 22
Joined: Mon Jan 18, 2010 4:15 pm

Re: manipulating the decision rules

Postby SébastienVillemot » Mon Nov 22, 2010 11:41 am

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,
Sébastien Villemot
Economist at OFCE – Sciences Po
SébastienVillemot
 
Posts: 706
Joined: Fri Dec 07, 2007 2:29 pm
Location: Paris, France

Re: manipulating the decision rules

Postby amfasolo » Thu Dec 09, 2010 1:45 pm

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
Attachments
unfoldg2.m
(1.03 KiB) Downloaded 183 times
amfasolo
 
Posts: 15
Joined: Thu Apr 09, 2009 5:57 pm
Location: Brazil

Re: manipulating the decision rules

Postby ian_db » Tue Dec 14, 2010 1:54 pm

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.
Attachments
DecR.m
Decision rules
(1.92 KiB) Downloaded 233 times
ian_db
 
Posts: 22
Joined: Mon Jan 18, 2010 4:15 pm

Re: manipulating the decision rules

Postby amfasolo » Tue Dec 14, 2010 4:19 pm

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
amfasolo
 
Posts: 15
Joined: Thu Apr 09, 2009 5:57 pm
Location: Brazil

Re: manipulating the decision rules

Postby chico » Fri Apr 13, 2012 10:50 am

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
chico
 
Posts: 2
Joined: Fri Apr 13, 2012 10:37 am

Re: manipulating the decision rules

Postby amfasolo » Mon Apr 16, 2012 1:08 am

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.
Attachments
unfoldg3.m
(1.77 KiB) Downloaded 150 times
amfasolo
 
Posts: 15
Joined: Thu Apr 09, 2009 5:57 pm
Location: Brazil

Re: manipulating the decision rules

Postby SamuelHurtado » Wed Nov 18, 2015 5:32 pm

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!
Attachments
unfoldg2.m
(1015 Bytes) Downloaded 104 times
Last edited by SamuelHurtado on Wed Nov 18, 2015 5:35 pm, edited 2 times in total.
SamuelHurtado
 
Posts: 7
Joined: Mon Feb 11, 2008 2:10 pm

Re: manipulating the decision rules

Postby SamuelHurtado » Wed Nov 18, 2015 5:32 pm

Can't upload two files to a single post, so here's the unfolder for G3
Attachments
unfoldg3.m
(1.04 KiB) Downloaded 100 times
SamuelHurtado
 
Posts: 7
Joined: Mon Feb 11, 2008 2:10 pm

Re: manipulating the decision rules

Postby jpfeifer » Wed Nov 18, 2015 6:57 pm

------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 15 guests