Optimal Policy with unusual welfare function

I’m trying to replicate a paper with a welfare function, that is a bit unusual. It looks like this:

W = E_0 \sum_{t=0}^\infty \beta^t \left\{-\frac{1}{2}W_\Pi\hat{\Pi}^2 -\frac{1}{2}W_Y(\hat{Y_t}-\hat{Y_t^*})^2 -\frac{1}{2}W_{\Delta_c}(\hat{C_{rt}}-\hat{C_{kt}})^2 \right\} + T_0 + t.i.p

, where T_0 is the unusual part, it contains terms, that only depend on gaps in t=0. t.i.p are terms independent of monetary policy.
T_0 depends on parameters and endogenous variables, it’s a huge term but is of the form:

T_0 = \sum_{t=0}^\infty \beta^t \left\{\frac{1-\alpha}{1+\phi} (\hat{Y_t} - \hat{A_t}) + (1-\alpha)(\hat{Y_t} - \hat{A_t})^2\right\}

I used this as guidance: DSGE_mod/Woodford_2003_Chapter_7.mod at master · JohannesPfeifer/DSGE_mod · GitHub, but I seem to get unusual results, so I thought I might have made a mistake when defining the planner objective.

Is this the correct way of how I would implement the above Welfare Function?:

planner_objective(-0.5*(Wpi * PiV^2 + Wy * (YV-YVS)^2 + Wdc * (CrV-CkV)^2) + To);

(I defined the \{\} part of T_0 as an endogenous variable to make the planner objective look less messy)

Hansen2020_Linearized_Ramsey.mod (3.6 KB)

You need to provide more context. What do you mean with

?
In your equations, T_0 is forward-looking and does not only contain t=0 variables.

From what I understand, normally a second order expansion of the welfare function (of the form: W = \sum \beta^t [ln(C_t) - N_t]), leads to a simple welfare function in quadratic gaps, but in the model I’m trying to replicate (this one), the steady-state is inefficient, which leads to extra terms depending linear on the output gap.
In order to circumvent this problem, the objective function is derived under timeless commitment, following Beningno and Woodford, 2005. The term T_0 is supposedly set at time zero, but I lack the theoretical understanding behind it and I don’t really understand what that means.
I was hoping I could still replicate the results in Dynare, given that I have the full quadratic gaps equation, but maybe it is not that easy.

I don’t see why you cannot simply use equation (26) in that paper and let Dynare approximate it.

When I try to use the nonlinear model and equation (26), I get an error, that the static model contains NaNs.
I thought this would happen, because the model has a distorted steady-state and I would need to readjust the steady-state model block somehow for this work. I was hoping I could circumvent the problem using the linear model and the quadratic gaps equation.
Is the steady-state not an issue?
Hansen2020_NotLinearized_Ramsey.mod (4.2 KB)

You cannot have model_diagnostics before defining the planner_objective.