
%close all
clear
clc
% addpath('functions')
%% Calibration

chi_v      = 2.10 ; % Reciprocal of labor supply elasticity
nu_v       = 1.30 ; % Capital Adjustment Cost Parameters 
psi_v      = 1.01 ; % Elasticity of substitution for services and goods
alpha_m_v  =  .5  ; % Share of service capital income 
alpha_n_v  =  .5  ; % Share of goods capital income 
l_ss_v     =   1  ;

xi_m_ss_v  = .85  ; % 稳态调价概率 
lota_m_v   = .50  ; % 通胀滞后系数
omega_m_v  = .0   ; % 选择强度参数//太高会出现超调

xi_n_ss_v  = .55  ; % 稳态调价概率 
lota_n_v   = .50  ; % 通胀滞后系数
omega_n_v  = .0   ; % 选择强度参数
 
rhor_v     = .6   ;
rho_m2_v   = .0   ;
rho_pi_v   = 1.5  ;
rhoy_v     = .10  ;

% ----- 实际经济
gam_gov_v  =  .15    ;  %  response of government consumption to debt 
gam_tra_v  =  .15    ;  %  response of transfer to debt
gam_tau_v  =  .15    ;  %  response of tax to debt

theta_v    = 0.0     ;  % 财政通胀参数

thetag_v   = 1.0  ;  % 支出冲击自筹资金比重
thetat_v   = 1.0  ;  % 税收冲击自筹资金比重

alp_v      = .54 ;  % 货物投入占比（校准）
AD_v       = 5   ;  % 平均债务期限

lam_v      = .25  ;
alp_g_v    = .10  ;

sb_ss_v    = 3.2    ;  % 政府债务占产出比值
sb_limit_v = 3.5    ;  % 债务极限

%% 基准模型
fid = fopen('definitions1.mod','wt');
fprintf(fid,' chi      = chi_v   ;\n') ; % 消费品货物投入占比
fprintf(fid,' nu       = nu_v    ;\n') ; % 投资品货物投入占比
fprintf(fid,' psi      = psi_v   ;\n') ;

fprintf(fid,' alp      = alp_v   ;\n') ; % 消费品货物投入占比
fprintf(fid,' AD       = AD_v    ;\n') ; % 债务期限
fprintf(fid,' theta    = theta_v ;\n') ; % 财政通胀系数
fprintf(fid,' thetat   = thetat_v;\n') ; % 自筹资金程度 
fprintf(fid,' thetag   = thetag_v;\n') ; % 自筹资金程度 

fprintf(fid,' alpha_m  = alpha_m_v    ;\n');
fprintf(fid,' alpha_n  = alpha_n_v    ;\n');

fprintf(fid,' rhor     = rhor_v       ;\n');
fprintf(fid,' rho_m2   = rho_m2_v     ;\n');
fprintf(fid,' rho_pi   = rho_pi_v     ;\n');
fprintf(fid,' rhoy     = rhoy_v       ;\n');

fprintf(fid,' xi_m_ss  = xi_m_ss_v  ;\n'); % 稳态调价概率 
fprintf(fid,' lota_m   = lota_m_v   ;\n'); % 通胀滞后系数
fprintf(fid,' omega_m  = omega_m_v  ;\n'); % 选择强度参数

fprintf(fid,' xi_n_ss  = xi_n_ss_v  ;\n'); % 稳态调价概率 
fprintf(fid,' lota_n   = lota_n_v   ;\n'); % 通胀滞后系数
fprintf(fid,' omega_n  = omega_n_v  ;\n'); % 选择强度参数

fprintf(fid,' gam_gov  = gam_gov_v  ;\n'); % 稳态调价概率 
fprintf(fid,' gam_tra  = gam_tra_v  ;\n'); % 通胀滞后系数
fprintf(fid,' gam_tau  = gam_tau_v  ;\n'); % 选择强度参数

fprintf(fid,' lam      = lam_v      ;\n'); % Rule of thumb
fprintf(fid,' alp_g    = alp_g_v    ;\n'); % 

fprintf(fid,' l_ss     = l_ss_v     ;\n'); % 稳态劳动

fprintf(fid,' sb_ss    = sb_ss_v    ;\n'); %  
fprintf(fid,' sb_limit = sb_limit_v ;\n'); % 

fclose(fid);

fid = fopen('definitions2.mod','wt');
fprintf(fid,'shocks(surprise);\n');
fprintf(fid,'var eps_govc;\n');
fprintf(fid,'periods 1;\n');
fprintf(fid,'values 1.05;\n');
fprintf(fid,'end;\n');

fprintf(fid,'occbin_setup;\n');
fprintf(fid,'occbin_solver(simul_periods=20,simul_check_ahead_periods=100, simul_maxit=100);\n');
fprintf(fid,'occbin_graph govc y tax c pi r def sb sbF;\n');
%fprintf(fid,'stoch_simul(order = 1, nomoments, nograph,noprint,pruning, periods = 1000);\n');
fprintf(fid,' Boo_ = oo_ ;\n');
fprintf(fid,' BM_  = M_  ;\n');
fclose(fid);

dynare NK_Occbin 


%% 脉冲响应图形：
horz = 20;

linewidth = 3;




