I have implemented second order welfare optimization and analysis for different policies used in the economy in the spirit of the methods, suggested on the forum Optimal policy parameters in a non-linear model
and specifically with reference to Professor Pfeifer DSGE_mod/Born_Pfeifer_2018/Welfare/.
Welfare analysis is with reference to paper by Quint and Rabanal (2014).

However, I am also interested in implementing the same procedure but with the Occasionally binding constraint (specifically, collateral constraint as in Iacoviello, 2005). As I understand Dynare inbuilt tools such as OccBin package uses first-order approximation around the steady state with its own simulation command, while Welfare measurement uses stoch_simul command and second-order approximation. That is where the problem arises - how to methods can be used together.

My question is whether it is possible with the tools and methods described above? If not, is there anything that can be done to evaluate optimal welfare policy rules and conduct welfare analysis, accounting for occasionally borrowing constraint?

I am not sure I got your point in the last message of the discussion.

The thing I wanted to do is to estimate optimal 2nd order Monetary Policy (MP) (Taylor Rule) that would maximize the welfare of agents, i.e. find such combination of MP parameters, such that welfare is maximized. To obtain this welfare I use stock_simul(order=2, irf=0), which is a basic tool for stochastic simulations. The I use solver and so on.

However, OccBin uses its own command occbin_solver, which takes given shocks as inputs.

The question is whether it is possible to find optimal (2nd order) MP given existence/possibility of occasionally binding constraint, such that this MP parameters are estimated with application of OccBin? Is it even feasible?

Would you be so kind, please, to refer me to any example or hint?

Or I should simply define conditional welfare within model-block in OccBin setup and then, given that I defined shocks for occbin_solver, I run a separate .mat file which optimizes parameters of a desired policy to maximize the conditional welfare by simulating the OccBin setup?

In other words, I substitute stoch_simul with occbin_solver, but other routine stays the same.

Yes, that is the right approach. But keep in mind, that this will yield a piecewise linear approximation to welfare. You need to verify whether that is sufficient for our purposes. Otherwise, Occbin is not suited.

Could you tell me please, when this might not be sufficient?
Maybe I misunderstand, but to me it is insufficient if I want to estimate 2nd order welfare, since piecewise method relies on first-order approximation approach.

Often optimal policy analysis is just about differences in variances around the steady state. If that is your object of interest, then second order should be needed. But with occasionally binding constraints, you may care mostly about differences in mean introduced by the constraint being differentially binding. I would recommend to have a look at the literature to see how they have proceeded in this case.