How to set external function onesidedhptrend_?

Hello everyone,
I am trying to use the onesidedhptrend command in my model, but dynare stops and it says something like:
Check for an incorrect parameter data type or missing parameters in the call to the function ‘onesidedhptrend_’.
The function used in my model is as follows:
variable …;

external_function(name = onesidedhptrend_,nargs=1);




Could anyone give me a hand? Thank you very much in advance!

What exactly are you trying to do here?

I want to make variable in gap form, that is, hpfiltered cycle of the variable.

Let me put it in detail.
In my model, I have variable b y, where b is bond, y is output. and I construct a third variable constructed from these two variables, b_y_ratio=b/y. I need gap form of the constructed ratiio variable in the model. That is ,variable b_y_ratio_gap which means the deviation of the ratio from its trend in my model.

Following the above warning are errors like:

error DSGE_model.static_resid_tt (line 225 )
TEF_0 = onesidedhptrend_(y(79)/y(55));

error DSGE_model.static_resid (line 19 )
    T = DSGE_model.static_resid_tt(T, y, x, params);

error DSGE_model.static (line 4 )
        residual = DSGE_model.static_resid(T, y, x, params, true);

error evaluate_static_model (line 63 )
        residuals = feval(fh_static,ys,exo_ss,params);

error evaluate_steady_state_file (line 108 )
    [residuals, check] = evaluate_static_model(ys, exo_ss, params, M, options);

error evaluate_steady_state (line 210 )
    [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, options,steadystate_check_flag);

error steady_ (line 55 )
[steady_state,params,info] = evaluate_steady_state(oo_.steady_state,M_,options_,oo_,~options_.steadystate.nocheck);

error steady (line 80)
[oo_.steady_state,M_.params,info] = steady_(M_,options_,oo_);

error DSGE_model.driver (line 2391 )

error dynare (line 293 )
evalin('base',[fname '.driver']) ;

error DSGE_model_loop (line232 )
dynare DSGE_model noclearall

I can’t understand what does it mean by these errors, can you help me? jpfeifer, many thanks.

But in your model, there is no trend. That’s why i am puzzled. In any case, it is possible to actually define a model-consistent HP-trend. See line 567 of DSGE_mod/BP2020_CES.mod at master · JohannesPfeifer/DSGE_mod · GitHub

You are right, jpfeifer. All the model variable has been detrended ones. But I need some variables in the gap form. How can I do that? I don’t know why I can’t open the link :sob:

Thank you jpfeifer,I’ve learned the BP2020.mod.Does it mean any other variable can be set in such way to get model-consistent variable gap? If I want to set HP-filtered b_y_ratio gap, I just only need to substitute the variable name for Y_hp_cyc as follows:
Am I understanding it corretly?Hoping to get your response, many many thanks.

Yes. It is well-known that the HP-trend is just a two-sided moving average with the weights above. The reference for that approach would be Has U.S. monetary policy tracked the efficient interest rate? - ScienceDirect or

Got it, thanks a lot.