global overwrite overwrite_param_names

%f_costs = 0.0055; % linear costs of banking
%sigmap_zero = 0.015;%.015; % affects + the spread, decrease the switches
zerop = 0;
gammap_targeted_ss = 0.078;

% baseline
betap = 1/(1+1.2831/400);   % discount factor leads to  sigmap_zero = 0.0377
%r_dp = 1/betap-0.6869/400;
r_dp = 1/betap-0.5531/400; % alternative with all deposits


% Begenau
%betap = 0.97;
%r_dp = 1+ 2.9063/400; % updated  Total interest expenses/liabilities
%r_dp = 1 + 0.0086; % from paper

% skander 
% betap = 1/(1+5.7120/400);   % discount factor
% r_dp = 1/betap-1.1602/400;


%r_dp = 1 + 0.86/100; %1+0.86/100
%rl_rd_spreadp = 2.26/100/4;

%rl_rd_spreadp = 1/0.99-r_dp;
f_costs = 0;

%r_dp = 1.01010101010
sigmap_c = 1.1; %2; % governs intertemporal elasticity of substitution =1 for log utility


taup = 0.042; %0.044; %0.05521; % for 10% capital requirements
%taup = 0.0463; % for 8% capital requirements


pip = pi;
recovery_ratiop = 1;

rho_gammap = 0.9;

kappap = 0;  %was 0

phip_i = 100;% in line with altig, christiano, et al. 10.78;  % based on Christiano, Motto and Rostagno; %0;

sigmap_d = 1.1;    % begenau 1.4  we use 1.1

gammap = 0.1;
gammap_increment = 0; %0.001; % for ISP shock 0.000001; %0.001;

alphap = 0.3;   % share in CD
deltap = 0.025; % depreciation rate
rhop_a = .95;  % shock persistence
rho_taup = 0.8;
rho_kap_quality = 0.5; %0.95;

sigma_bar = 0.99; % was 0.99 %0.08% share of risky firms
sigma_lower_bar = 0.01; 


%xip = 0.00025;  %0.1; % governs spread between risky and riskier loans
xip = 0.0005; %0.000764; %0.00025;
sigma_eps_a = 0.015; % standard deviation of the TFP shock


sigma_eps_kap_quality = 0; %0.000375;  % only effective for the calibration model
sigma_eps_isp = 0.01*30/1.052503836875867; % only effective for the calibration model

sigma_eps_tau = 0.0015;

F_costs = 0; % fixed costs of banking
kappab = 0.0;%0.02; % proportional cost of equity
rho_isp = 0.8;

% parameters governing the rule for gamma when deviating from the Ramsey
% policy
q_gammap = 0;
k_gammap = 0;
d_gammap = 0;
c_gammap = 0;
ginvest_gammap = 0;
l_gammap = 0;
ltot2ytot_gammap = 0;
r_d_gammap=0;
r_l_lead_gammap=0;
banking_spread_gammap = 0; 
ytot_gammap = 0;
a_gammap = 0;
isp_gammap = 0;
tau_gammap = 0;
eps_a_gammap = 0;
eps_isp_gammap = 0;
eps_tau_gammap = 0;
chi2_upper_bar_gammap = 0;

load my_estimates_constraints_spreads_my;

estimated_param_names = char('sigma_eps_a','sigma_eps_isp','sigma_eps_tau',...
   'rhop_a','rho_isp','rho_taup','phip_i','kappap','xip','taup');
if ~isempty(overwrite)
    % find common names (and their indices) of the parameters
    % that you would like to overwrite
    % and the parameters that you estimated and loaded
    [common_names, i_overwrite, i_estimated] = intersect(overwrite_param_names, estimated_param_names,'rows');
    n_common = size(common_names,1);
    % for the commmon parameters: use the values in overwrite
    for this_parm = 1:n_common
        distance_param(i_estimated(this_parm)) = overwrite(i_overwrite(this_parm));
    end
    % for the parameters that are present only in overwrite_param_names: add
    % them to the list of estimated_parameters
    n_new = length(overwrite)-n_common;
    [new_names, i_new_overwrite, i_common] = setxor(overwrite_param_names, common_names,'rows','stable');
    for this_parm = 1:n_new
        estimated_param_names = union(estimated_param_names,new_names(this_parm,:),'rows','stable');
        distance_param(end+1) = overwrite(i_new_overwrite(this_parm));
    end
end
% Adjusted overwrite parameters
overwrite = distance_param;
overwrite_param_names = estimated_param_names;

%overwrite_param_names = char('sigma_eps_a','sigma_eps_isp','sigma_eps_tau',...
%   'rhop_a','rho_isp','rho_taup','phip_i','kappap','xip','taup','gammap_increment');

%overwrite = [distance_param; gammap_increment];

if ~isempty(overwrite)
    nchanges = length(overwrite);
    for this_parm = 1:nchanges
        eval([overwrite_param_names(this_parm,:),'= overwrite(this_parm);'])
    end
end