clear
 
cd('/Users/mehreganameri/Google Drive/Academic/PhD/Model/1HH/NS')
addpath /Applications/Dynare/4.4.3/matlab;
%addpath /Applications/Dynare/4.4_2013-10-23/matlab;

%% Set parameters
nu = 0.7;           % fraction of non-stockholders
upsilon = 8.92;        % power of N in utility function
beta=0.998;          % discount factor
theta=0.65;          % P of adjusting price
epsilon=10;          % elasticity of substitution of goods
phi_p=1.5;         % response of CB to Pi
phi_y=0.5;          % response of CB to y^tilda
sigma_a=0.1;      % se of innovation to productivity
sigma_r=0.24;       % se of of innovation to R
rho_a=1.1;         % persistence of innovation to prductivity
rho_r=0.12;         % persistence of innovation to R

parameters = [nu upsilon beta theta epsilon phi_p phi_y sigma_a sigma_r rho_a rho_r];


%% Solving for steady state
X0=ones(16,1);

X0(3)	=	0;
X0(4)	=	beta;
X0(5)   =	1/beta;
X0(6)  =	(epsilon-1)/epsilon;
X0(12)	=	(epsilon-1)/epsilon;

Z=fsolve(@steady_stateNS,X0,[],parameters); 


%% Extracting SS values
C_ss     = Z(1);
N_ss     = Z(2);
B_P_ss   = Z(3);
Lambda_ss= Z(4);
R_ss      = Z(5);
W_P_ss    = Z(6);
Pi_ss     = Z(7);
D_P_ss    = Z(8);
Y_ss      = Z(9);
Pstar_P_ss= Z(10);
s_ss      = Z(11);
MC_P_ss   = Z(12);
Gamma1_ss = Z(13);
Gamma2_ss = Z(14);
eps_a_ss  = Z(15);
eps_r_ss  = Z(16);

save parameters nu upsilon beta theta epsilon phi_p phi_y sigma_a sigma_r rho_a rho_r C_ss N_ss B_P_ss Lambda_ss ... 
        R_ss W_P_ss Pi_ss D_P_ss Y_ss Pstar_P_ss s_ss MC_P_ss Gamma1_ss Gamma2_ss eps_a_ss eps_r_ss;


%% after having run the mod-file:
%% first order:
%set_param_value('delta',d);
dynare nk.mod;
%%
%plot(sp_eta_R);
%print('-dpdf','sp_eta_R');
%plot(sw_eta_R);
%print('-dpdf','sw_eta_R');

%% second order with pruning:

%dynare newkeynesian_pruning;
%%
%plot(sp_eta_R);
%print('-dpdf','sp_eta_R_pruning');
%plot(sw_eta_R);
%print('-dpdf','sw_eta_R_pruning');

varD_all = oo_.gamma_y{7};
var_all = oo_.var;
mean_all = oo_.mean;

save('varD_all', 'varD_all');
save('var_all', 'var_all');
save('mean_all', 'mean_all');
