function welfare = optimal_rule_fminsearch(RP1,RY1,TP1,TY1,RR1,TT1)


global M_ oo_ options_ 

try 
opt_rule1;

var_list_=[];
var_list_ = 'totutility';
var_list_ = char(var_list_, 'tau');

set_param_value('RP',RP1);
set_param_value('RY',RY1);
set_param_value('TP',TP1);
set_param_value('TY',TY1);
set_param_value('RR',RR1);
set_param_value('TT',TT1);

set_dynare_seed('default');;
options_.order = 2;
info = stoch_simul(var_list_);
%uncondition welfare
welfare =  -oo_.mean(1);

load result1
%resirf == 1;
if length(find(abs(real(oo_.dr.eigval))>1+1e-3))~=19 | length(find(abs((oo_.dr.eigval))<1-1e-6))~=33  | oo_.mean(2)>1 | oo_.mean(2)<0 | resirf == 0| isnan(welfare) | abs(RPv)>100 |abs(RYv)>100 | abs(TPv)>100| abs(TYv)>100
 welfare = 1e10;
end;

catch 
    welfare = 1e10;
end
