Understanding Dynare Second Order Policy Functions

Hello there,

I have a dynare code that runs fine. The dynare code generates a simulation with 1000 periods.
I am trying to replicate that exact simulation using the policy functions dynare outputs to the screen as well as the shocks that dynare stores in oo_.exo_simul.

However, for some reason I cannot replicate the exact same results that dynare has. I am attaching the dynare code and the matlab code that tries to replicate the dynare simulation for my first variable (p2).

There must be something that I am not understanding in the way dynare stores the coefficients of the policy functions and uses them to compute the decisions.

Edit: After reading this other topic, I removed the +1e-14 part of line 164 of stoch_sim. The differences indeed decreased but are still there …

model.mod (2.4 KB)
simreplication.m (8.6 KB)

Users probably won’t have the time to check whether you correctly created the respective cross-terms and matched them to the value of the decision rules. But it is obvious that you are not using the right initial conditions. With pruning you will have an augmented state space. You cannot simply start with the first endogenous simulation period p2(2), but would need to start at the same initial condition (which is not provided as an output)