I’m new to Dynare! I derived all the F.O. conditions for my model and I’m confused how to write them in mod file. My aim is to find the optimal monetary policy rule for Small open economy. My understanding is that I need to solve the model first before I find the optimal rules. Also, I need to write the model in nonlinear form. I have few question, would appreciate it any help really!
 Is the following way correct to enter the model in the codes?
This is the F.O. C. with respect to (k t+1 )  which is the capital with cost adjustment investment.
psii*((k(+1)/k)1)+1=betta*(lammbda(+1)/lammbda)*(1+rk(+1)deltta+((psii/2)*((k(+2)/k(+1))1)));
 how to write the monetary policy rule ? I have it as following but not sure if it is right.
where v follows AR(1) process.
 How to write the AR(1) process shocks in the code?
I will give two examples. one is the productivity shock, and the other one is the monetary policy shock.
Please note that I write V in the monetary policy rule as specified above and I write A in the production function as following:
Basically what I did is I copied the F.C C. into the codes but really not sure if that’s the way to do it.
I really appreciate any help !!! Thanks for your time!
 I think there is a term missing (product rule). Take a look at the AguiarGopinath2007.mod on my homepage. There you would obtain something like:
uc*(1+phi*(k(+1)/k1))=beta*uc(+1)*(1delta+(1alpha)*y(+1)/k(+1)phi/2*(2*(k(+2)/k(+1)1)*(1)*k(+2)/k(+1)+(k(+2)/k(+1)1)^2));
2. This is almost correct, but you need
because v has steady state 0. Otherwise, the n on the RHS would make the RHS 0, but it must be 1.
3. The same as in 2. applies here. TFP typically follows a lognormal process. If you specify A as normal mean 0 process, you must use
Otherwise, the RHS will again be 0 in steady state.
4. Note that the way you entered the timing for k, you are violating Dynare’s end of period stock timing convention and require
This was VERY helpful Johannes, I truly appreciate your help. I have more questions if you don’t mind:

I notice that my nonlinear model is very sensitive to the parameters values. You could change one parameter and ended up with non zero residuals of the static equations, does that mean the model is bad? or this is usually what we expect with DSGE models.

to be able to loglinearize the model by dynare, do I need to only take the exp for every variable I have? Are there any materials could help with that?
Confusion: I understand that in economics it is always easier to interpret the loglinearized models. But if I loglinearize my model, and since I was able to find the impulse responses of the nonlinear version of it, do I expect to see the impulse responses of the loglinearized one by default? and do we expect to see the same dynamic of the impulse responses? I assume we should but I heard some ppl had problem with that part.
 My aim is to find the optimal monetary policy responses and optimal monetary policy rule. Could you please refer me to any codes or materials on that for small open economies? Also, to be able to find the optimal monetary policy rule, do I need only the nonlinear system without taking any exp of the variables?
Again, I appreciate all the help!!!
I appreciate your help Johannes, I’m still working on coding the model. Just quick question, Lets say that I have an exogenous shock in the model like foreign price which we usually assume it follows AR(1). Would it be acceptable if I estimate that my self? in another word, if I regress the variable on its first lag and take the beta and the st of the estimated regression to be used in calibrating the exogenous shock of foreign price in the DSGE model. Thanks alot!!
If the process is exogenous, you can do that. It is what Kydland/Prescott originally did.