Pruning and Euler residuals

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.

Pruning and Euler residuals

Postby macroresearch123 » Wed Jul 09, 2014 6:36 pm

Hi Johannes,

When you have a minute, I have two related questions based on comparisons between the solution provided by Dynare's perturbations and a projection method I am doing for one of my papers. As we are aware, second order perturbations can lead to explosive simulations. Although I can compute the cross correlations of my simulated endogenous variables produced by the stoch_simul command, when I try to simulate starting from the steady state (not using the simulated values Dynare automatically produced) in order to compute the Euler residuals, I encounter an explosive solution. Therefore, I was using the pruning technique suggested by Fernandez. In particular, it looked like:

stoch_simul(periods=1000, drop=200, solve_algo=0, order=2, nograph, noprint);
simulations=pruning_abounds(M_,options_,order=2,'kim_et_al');

However, upon that format and other alterations, I could not get it to work. I looked extensively online, but no sample code seems to exist publicly. What should I change to prune my second order perturbation?

Related to that, are you aware of documentation on computing Euler residuals? I have a method where I essentially construct the equations as they are articulated in Judd's paper, but I was interested in comparing if there's other code available. I saw some material from Wouter Den Haan, but it's hard to read without a pdf of the model and what each line of code is derived from.

Thank you as always for your help!
macroresearch123
 
Posts: 90
Joined: Wed Nov 06, 2013 3:28 pm

Re: Pruning and Euler residuals

Postby jpfeifer » Thu Jul 10, 2014 11:46 am

For the reference, I would have to look.

Why don't you use Dynare's pruning option, which is the Kim et al one?
------------
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

Re: Pruning and Euler residuals

Postby macroresearch123 » Thu Jul 10, 2014 2:47 pm

Indeed, that was the one I was trying to use via Fernandez's package; I wasn't able to find any documentation by Dynare on it -- just his package that goes with it. However, the code and lots of variations of it that are in the readme did not work.
macroresearch123
 
Posts: 90
Joined: Wed Nov 06, 2013 3:28 pm

Re: Pruning and Euler residuals

Postby macroresearch123 » Tue Jul 15, 2014 2:21 pm

Just to clarify, I am still unsure about how to do pruning in Dynare. Although it is noted in the manual, the command "pruning=1" and variants of it do not work for me. Any suggestions on the computation of Euler residuals would also be helpful!
macroresearch123
 
Posts: 90
Joined: Wed Nov 06, 2013 3:28 pm

Re: Pruning and Euler residuals

Postby jpfeifer » Tue Jul 15, 2014 2:42 pm

In Dynare 4.4.2 the correct Kim et al/Andreasen et al pruning is conducted whenever you use pruning=1. Which type of problem do you encounter?

Regarding Euler errors, the only source I can come up with on top of my head is the Fortran code of Aruoba et al (2006): "Comparing solution methods for dynamic equilibrium economies" at http://economics.sas.upenn.edu/~jesusfv/companion.htm But this requires some digging. I always wanted a Matlab version of that code. So if you go ahead an succeed, I would be grateful if you could share it.
------------
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

Re: Pruning and Euler residuals

Postby macroresearch123 » Tue Jul 15, 2014 4:11 pm

Thank you for the reply! I attached the file -- it's very similar to what you've already seen in my file before; just note at the bottom that pruning is included in the options. If I instead use "pruning=1", Dynare encounters an error. In particular, it says "DYNARE: preprocessing failed". I have tried various alterations to that command.

If I can get the pruning to work, I should have a working Euler residual code -- at least one version that computes it; I will gladly share it with you/ others after I get it working in my paper (and tested). I was just curious how others computed their accuracy -- but it seems documentation of these methods is just so scarce. Thanks for the other reference too, which I will check, though not familiar with Fortran.
Attachments
benchmarkcb.mod
(4.32 KiB) Downloaded 63 times
macroresearch123
 
Posts: 90
Joined: Wed Nov 06, 2013 3:28 pm

Re: Pruning and Euler residuals

Postby jpfeifer » Tue Jul 15, 2014 4:17 pm

The syntax to enable pruning is just
Code: Select all
stoch_simul(order=2,pruning);

and not
Code: Select all
stoch_simul(order=2,pruning=1);
------------
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

Re: Pruning and Euler residuals

Postby macroresearch123 » Tue Jul 15, 2014 6:19 pm

Right, I tried that too, but when I simulated my time series it still exploded. (That's why I thought I was doing it incorrectly.) I'll send you a message with details.
macroresearch123
 
Posts: 90
Joined: Wed Nov 06, 2013 3:28 pm

Re: Pruning and Euler residuals

Postby macroresearch123 » Tue Jul 29, 2014 5:47 am

Hi Johannes,

Adding to our last email conversation: One peculiarity that I encountered is that my simulated time series explodes sometimes, and other times it does not -- I am not sure what causes it to happen. (I have pruning on each case.) I implemented what you suggested -- using Dynare's simult_ command -- via code you posted in another thread:
[dr,~,M,~,oo] = resol(0,M_,options_,oo_);
y_ = simult_(oo_.steady_state,dr,oo_.exo_simul,2);

However, to calculate the dynamic Euler residuals, I need to use Gauss Hermite; using the two node example I showed you before, it might take the form of
y_plus = SS + A*(ye2(:, t) - SSe) + B*shocks(:,t);
y_minus = SS + A*(ye2(:, t) - SSe) - B*shocks(:,

With that in mind, two clarifying questions:
1) Why does simult_ produce time series that do not explode, but when I apply the decision rules (see the bottom of this message), it explodes?
2) Is there a way to incorporate simult_ to do Gauss Hermite quadrature? I googled "simult_" and literally only one other dynare thread comes up -- no one seems to use it!

Example of decision rules:
for t = 2:Tsim;
y_2(:,t)=SS+.5*del2+A*(ye2(:,t-1)-SSe)+B*shocks(:,t) ...
+.5*C*kron(ye2(:,t-1)-SSe,ye2(:,t-1)-SSe) ...
+.5*D*kron(shocks(:,t),shocks(:,t))+E*kron(ye2(:,t-1)-SSe,shocks(:,t));
ye2(:,t)=y_2(statevars,t);
end
macroresearch123
 
Posts: 90
Joined: Wed Nov 06, 2013 3:28 pm

Re: Pruning and Euler residuals

Postby jpfeifer » Wed Jul 30, 2014 12:29 pm

What you need is the value of the policy function given today's state and new period's shock, with the shock once being positive and once being negative. This can be easily done using simult_. simult_ has a syntax where you provide the initial condition and the shocks. From the "pure news shock" model on my homepage:
Code: Select all
//initialize IRF generation
initial_condition_states = repmat(oo_.dr.ys,1,M_.maximum_lag);
shock_matrix = zeros(options_.irf,M_.exo_nbr); %create shock matrix with number of time periods in colums

// set shocks for pure news
shock_matrix(1,strmatch('eps_z_news',M_.exo_names,'exact')) = 1; %set news shock to 1 (use any shock size you want)
y2 = simult_(initial_condition_states,oo_.dr,shock_matrix,1);
y_IRF = y2(:,M_.maximum_lag+1:end)-repmat(oo_.dr.ys,1,options_.irf); %deviation from steady state


Thus, you need to call simult_ twice, once with a positive shock and once with a negative shocks. It will provide you with the policy function value for all variables. You also only need to simulate for one period instead of oo_.irf periods.

The difference by the way is that your policy functions do not implement pruning. You do not have an augmented state space there.
------------
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

Re: Pruning and Euler residuals

Postby macroresearch123 » Fri Aug 01, 2014 5:17 am

I am always amazed at how well you know this software! I think I followed your suggestion properly. Since the y_2 in the following code is what explodes, I just replace it with "policyfunc", which is equivalent to the y_2 in your quoted code. The accuracy of the solution doesn't look that great, so I am also in the process of coding my model up in GSSA. Just so much harder to do analysis in it... writing IRFs by hand, etc!

for t = 2:Tsim;
y_2(:,t)=SS+.5*del2+A*(ye2(:,t-1)-SSe)+B*shocks(:,t) ...
+.5*C*kron(ye2(:,t-1)-SSe,ye2(:,t-1)-SSe) ...
+.5*D*kron(shocks(:,t),shocks(:,t))+E*kron(ye2(:,t-1)-SSe,shocks(:,t));

y_2(:,t)=policyfunc(:,t);
ye2(:,t)=y_2(statevars,t);
end
macroresearch123
 
Posts: 90
Joined: Wed Nov 06, 2013 3:28 pm

Re: Pruning and Euler residuals

Postby jpfeifer » Fri Aug 01, 2014 5:40 am

I don't understand what you are doing. You are supposed to use the y_2 as the whole policy function. It already is the full pruned solution that must be entered in evaluating the expectation
------------
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

Re: Pruning and Euler residuals

Postby macroresearch123 » Fri Aug 01, 2014 4:14 pm

Right -- I didn't post that part of my code since I didn't want to take more of your time, but that's what I am doing: use the simulated "simult_" as the policy function, instead of what I would have otherwise done to create the policy function via Dynare's oo_.dr.ghx etc variables (what you saw above). Once that ye2 is created, then I can set up two quadrature nodes (i.e. below) and evaluate expectations.

y_plus = SS + A*(ye2(:, t) - SSe) + B*shocks(:,t);
y_minus = SS + A*(ye2(:, t) - SSe) - B*shocks(:,t);
macroresearch123
 
Posts: 90
Joined: Wed Nov 06, 2013 3:28 pm

Re: Pruning and Euler residuals

Postby jpfeifer » Sat Aug 02, 2014 8:31 am

I still don't get it. The result of simult_ is the full right-hand side, including the shock response. It looks as if you are using the shock a second time.
------------
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: No registered users and 5 guests