# Simulation using Policy functions

Hi everyone,

I ask for the following help:

I attempted to understand how the second-order approximation worked in Dynare. I specified a value for periods, provided the initial value close enough to the steady state and typed “steady”, so I generated a stochastic simulation starting from the steady state. Then I found the results of policy functions. Following the reference manual, I set down the following lines in Matlab:

periods=1000;
Variablenumber=24;
y_sim=zeros(Variablenumber,periods);
y_sim(:,1)=oo_.dr.ys+0.5oo_.dr.ghs2+oo_.dr.ghxzeros(5,1)+oo_.dr.ghuoo_.exo_simul(1,:)’+0.5oo_.dr.ghxxzeros(25,1)+0.5oo_.dr.ghuu*
kron(oo_.exo_simul(1,:)’,oo_.exo_simul(1,:)’)+oo_.dr.ghxu*kron(zeros(5,1),oo_.exo_simul(1,:)’);

Here zeros(5,1) means that I have 5 endogeneous state variables and that the difference of them compared to the steady state is zero since I simulate from the steady state. But the result of the simulation in the first period differs from the simulation conducted by Dynare, which was correct. I wonder where I made a mistake.

I am not entirely sure what you are doing, but
1.) `oo_.exo_simul` is supposed to be for perfect foresight simulations.
2.) There is a difference between the declaration order of oo_.dr.ys and the declaration order of the gh-matrices. See simult_.m for the way Dynare conducts simulations.