How do I write the code of this objective function?

Indeed, the objective function in OSR is the second moments, that is,

lambda *var(yt) + var(pit).

But my objective is

lambda* (yt - y*)^2 + (pit - pi*)^2.

Where y* is the target value of yt. So could you help tell me how I can write the code of this objective function?

1 Like

The way OSR works in Dynare, it does not allow for user-defined welfare functions. The function needs to be representable in the form of second moments only. If your variables are not at the target on average, you will have linear terms in your objective. In that case, you need to run an optimizer over the parameter given the welfare objective. See e.g. Loop over parameters to find maximized welfare