%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Replication code for article
% Title: Optimal Portfolio Choice in a General Equilibrium Model with Portfolio Frictions and Short-Selling Constraint
% authors: Simon Tièche and Didier Cossin
% corresponding author: Simon Tièche, simon.tieche@imd.org

% Execute this code to reproduce the figures
% the code also executes the file: GE_mathematics_3645427.mod
% the code needs DynareMatlab

clear all
close all
clc

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Indicate user
user = 1;

if user == 1 % 
    addpath('C:\dynare\5.2\matlab') % path to dynare
    path = 'PATH USER 1';
    figpath = 'PATH USER 1';
elseif user == 2 
    addpath('')
    path = 'PATH USER 2';
    figpath = 'PATH USER 2';

end
cd(path)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Parameters other than risk aversion and portfolio friction
beta11 = 0.95;
delta11 = 0.05;
theta11 = 0.33;
zeta11 = 15;
zbar11 = 0.5;
sigma2er = 0.00076;

shock = 0.02; % corresponds to 1% SHOCK in Firm's 1 technology innovation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Main results

mu = 900; % benchmark cost of portfolio adjustment
gamma = 5; % benchmark risk aversion
SHOCK = [0.02 0.025 0.02]; % shock1: no portfolio response, shock2: no non-negativity constraint, shock3: non-negativity constraint

a111 = 2*mu/( gamma + (1+beta11)*mu + sqrt( gamma^2 + (1-beta11)^2*mu^2 + 2 * (1+beta11)*gamma*mu) );
a211 = a111/(mu*sigma2er);

hor = 201;
[z_shock, D_1_shock, D_2_shock, W_shock,R_1_shock, R_2_shock, Q_1_shock, Q_2_shock, K_1_shock, K_2_shock, Y_1_shock, Y_2_shock, CH_1_shock, CH_2_shock] = deal(zeros(hor,length(SHOCK))); 
[a1_shock, a2_shock] = deal(zeros(1,length(SHOCK)));
for i = 1:length(SHOCK)

    if i == 1
        DDUMMY = 0;
    else
        DDUMMY = 1;
    end
    
    shock = SHOCK(i);
    
    a1_shock(i) = a111;
    a2_shock(i) = a211;

    % simulate model
    dynare GE_mathematics_3645427 noclearall;

    z_shock(:,i) = z_e; % portfolio share
    W_shock(:,i) = W_e; % wealth
    R_1_shock(:,i) = R_1_e; % firm 1 return
    R_2_shock(:,i) = R_2_e; % firm 2 return
    Q_1_shock(:,i) = Q_1_e; % firm 1 asset price
    Q_2_shock(:,i) = Q_2_e; % firm 2 asset price
    K_1_shock(:,i) = K_1_e; % firm 1 capital
    K_2_shock(:,i) = K_2_e; % firm 2 capital
    Y_1_shock(:,i) = Y_1_e; % firm 1 output
    Y_2_shock(:,i) = Y_2_e; % firm 2 output
    D_1_shock(:,i) = D_1_e; % firm 1 dividend
    D_2_shock(:,i) = D_2_e; % firm 2 dividend
    CH_1_shock(:,i) = CH_1_e; % HH 1 consumption
    CH_2_shock(:,i) = CH_2_e; % HH 2 consumption
    
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% FIGURES: setup
close all;

black = [0 0 0];
grey = 0.3*[1 1 1];
xxlim = 50;

yylabel = 'Percentage (%)';
ratio = 0.6;
w = 20; 
h = w*ratio;

%% SHOCK figures
fig = figure;
hold on;
hplot1 = plot(100*z_shock(:,1),'color', [0.7 0.7 0.7] , 'LineWidth', 1.2, 'LineStyle',':', 'DisplayName','No Portfolio Response','Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim  )  ;
hplot2 = plot(100*z_shock(:,2),'color', [0.3 0.3 0.3] ,'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained'); 
hplot3 = plot(100*z_shock(:,3),'color', [0.0 0.0 0.0] ,'LineWidth', 1.2, 'LineStyle','-' ,'DisplayName','Constrained'); 
hplot4 = plot(z_shock(1,1)*zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel('Percentage Points')
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'z_shock_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Q_1_shock(:,1), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle',':', 'DisplayName','No Portfolio Response','Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim  )  ;
hplot2 = plot(100*Q_1_shock(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained');
hplot3 = plot(100*Q_1_shock(:,3), 'color', [0.0 0.0 0.0] ,'LineWidth',1.2, 'LineStyle','-' ,'DisplayName','Constrained'  ); 
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Q_1_shock_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Q_2_shock(:,1), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle',':', 'DisplayName','No Portfolio Response','Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim  )  ;
hplot2 = plot(100*Q_2_shock(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained');
hplot3 = plot(100*Q_2_shock(:,3), 'color', [0.0 0.0 0.0] ,'LineWidth',1.2, 'LineStyle','-' ,'DisplayName','Constrained'  ); 
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','northeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Q_2_shock_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*K_1_shock(:,1), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle',':', 'DisplayName','No Portfolio Response','Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim  )  ;
hplot2 = plot(100*K_1_shock(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained');
hplot3 = plot(100*K_1_shock(:,3), 'color', [0.0 0.0 0.0] ,'LineWidth',1.2, 'LineStyle','-' ,'DisplayName','Constrained'  ); 
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','north');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'K_1_shock_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*K_2_shock(:,1), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle',':', 'DisplayName','No Portfolio Response' ,'Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim )  ;
hplot2 = plot(100*K_2_shock(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained');
hplot3 = plot(100*K_2_shock(:,3), 'color', [0.0 0.0 0.0] ,'LineWidth',1.2, 'LineStyle','-' ,'DisplayName','Constrained'  ); 
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','northeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'K_2_shock_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*R_1_shock(:,1),'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--', 'DisplayName','No Portfolio Response' ,'Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim  )  ;
hplot2 = plot(100*R_1_shock(:,2),'color', [0.3 0.3 0.3] ,'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained'); 
hplot3 = plot(100*R_1_shock(:,3),'color', [0.0 0.0 0.0] ,'LineWidth', 1.2, 'LineStyle','-' ,'DisplayName','Constrained'); 
hplot4 = plot(R_1_shock(1,1)*zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel('Percentage Points');
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'R_1_shock_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*R_2_shock(:,1),'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--', 'DisplayName','No Portfolio Response' ,'Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim  )  ;
hplot2 = plot(100*R_2_shock(:,2),'color', [0.3 0.3 0.3] ,'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained'); 
hplot3 = plot(100*R_2_shock(:,3),'color', [0.0 0.0 0.0] ,'LineWidth', 1.2, 'LineStyle','-' ,'DisplayName','Constrained'); 
hplot4 = plot(R_1_shock(1,1)*zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel('Percentage Points');
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'R_2_shock_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Y_1_shock(:,1), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle',':', 'DisplayName','No Portfolio Response' ,'Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim )  ;
hplot2 = plot(100*Y_1_shock(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained');
hplot3 = plot(100*Y_1_shock(:,3), 'color', [0.0 0.0 0.0] ,'LineWidth',1.2, 'LineStyle','-' ,'DisplayName','Constrained'  ); 
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Y_1_shock_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Y_2_shock(:,1), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle',':', 'DisplayName','No Portfolio Response' ,'Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim )  ;
hplot2 = plot(100*Y_2_shock(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained');
hplot3 = plot(100*Y_2_shock(:,3), 'color', [0.0 0.0 0.0] ,'LineWidth',1.2, 'LineStyle','-' ,'DisplayName','Constrained'  ); 
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','northeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Y_2_shock_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*D_1_shock(:,1), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle',':', 'DisplayName','No Portfolio Response' ,'Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim )  ;
hplot2 = plot(100*D_1_shock(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained');
hplot3 = plot(100*D_1_shock(:,3), 'color', [0.0 0.0 0.0] ,'LineWidth',1.2, 'LineStyle','-' ,'DisplayName','Constrained'  ); 
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'D_1_shock_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*D_2_shock(:,1), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle',':', 'DisplayName','No Portfolio Response','Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim  )  ;
hplot2 = plot(100*D_2_shock(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained');
hplot3 = plot(100*D_2_shock(:,3), 'color', [0.0 0.0 0.0] ,'LineWidth',1.2, 'LineStyle','-' ,'DisplayName','Constrained'  ); 
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','northeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'D_2_shock_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*W_shock(:,1), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle',':', 'DisplayName','No Portfolio Response' ,'Marker','o', 'MarkerSize',3,'MarkerIndices',1:5:xxlim )  ;
hplot2 = plot(100*W_shock(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','Not Constrained');
hplot3 = plot(100*W_shock(:,3), 'color', [0.0 0.0 0.0] ,'LineWidth',1.2, 'LineStyle','-' ,'DisplayName','Constrained'  ); 
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2, hplot3],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'W_shock_new','.pdf'))

close all;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Simulation with different risk aversion: GAMMA
shock = 0.02; 
mu = 900;
GAMMA = [5, 10000];

[z_gamma, D_1_gamma, D_2_gamma, W_gamma,R_1_gamma, R_2_gamma, Q_1_gamma, Q_2_gamma, K_1_gamma, K_2_gamma, Y_1_gamma, Y_2_gamma, CH_1_gamma, CH_2_gamma] = deal(zeros(hor,length(GAMMA))); 
[a1_gamma, a2_gamma] = deal(zeros(1,length(GAMMA)));
for i = 1:length(GAMMA)
    gamma = GAMMA(i);

    a111 = 2*mu/( gamma + (1+beta11)*mu + sqrt( gamma^2 + (1-beta11)^2*mu^2 + 2 * (1+beta11)*gamma*mu) );
    a211 = a111/(mu*sigma2er);
    
    a1_gamma(i) = a111;
    a2_gamma(i) = a211;

    % simulate model
    dynare GE_mathematics_3645427 noclearall;

    z_gamma(:,i) = z_e; % portfolio share
    W_gamma(:,i) = W_e; % Wealth
    R_1_gamma(:,i) = R_1_e; % firm 1 return
    R_2_gamma(:,i) = R_2_e; % firm 2 return
    Q_1_gamma(:,i) = Q_1_e; % firm 1 asset price
    Q_2_gamma(:,i) = Q_2_e; % firm 2 asset price
    K_1_gamma(:,i) = K_1_e; % firm 1 capital
    K_2_gamma(:,i) = K_2_e; % firm 2 capital
    Y_1_gamma(:,i) = Y_1_e; % firm 1 output
    Y_2_gamma(:,i) = Y_2_e; % firm 2 output
    D_1_gamma(:,i) = D_1_e; % firm 1 dividend
    D_2_gamma(:,i) = D_2_e; % firm 2 dividend
    CH_1_gamma(:,i) = CH_1_e; % HH 1 consumption
    CH_2_gamma(:,i) = CH_2_e; % HH 2 consumption
    
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% GAMMA figures
fig = figure;
hold on;
hplot1 = plot(100*z_gamma(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5' )  ;
hplot2 = plot(100*z_gamma(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\gamma = 1000');
hplot4 = plot(z_gamma(1,1)*zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel('Percentage Points')
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'z_gamma_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Q_1_gamma(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5'  )  ;
hplot2 = plot(100*Q_1_gamma(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\gamma = 1000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Q_1_gamma_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Q_2_gamma(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5'  )  ;
hplot2 = plot(100*Q_2_gamma(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\gamma = 1000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Q_2_gamma_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*K_1_gamma(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5'  )  ;
hplot2 = plot(100*K_1_gamma(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\gamma = 1000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'K_1_gamma_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*K_2_gamma(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5' )  ;
hplot2 = plot(100*K_2_gamma(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\gamma = 1000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'K_2_gamma_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*R_1_gamma(:,1),'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5'  )  ;
hplot2 = plot(100*R_1_gamma(:,2),'color', [0.3 0.3 0.3] ,'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\gamma = 1000'); 
hplot4 = plot(R_1_gamma(1,1)*zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel('Percentage Points');
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'R_1_gamma_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*R_2_gamma(:,1),'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5'  )  ;
hplot2 = plot(100*R_2_gamma(:,2),'color', [0.3 0.3 0.3] ,'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','\gamma = 1000'); 
hplot4 = plot(R_1_gamma(1,1)*zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel('Percentage Points');
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'R_2_gamma_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Y_1_gamma(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5' )  ;
hplot2 = plot(100*Y_1_gamma(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\gamma = 1000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Y_1_gamma_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Y_2_gamma(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5' )  ;
hplot2 = plot(100*Y_2_gamma(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\gamma = 1000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Y_2_gamma_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*D_1_gamma(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5' )  ;
hplot2 = plot(100*D_1_gamma(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\gamma = 1000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'D_1_gamma_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*D_2_gamma(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5' )  ;
hplot2 = plot(100*D_2_gamma(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\gamma = 1000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'D_2_gamma_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*W_gamma(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\gamma = 5' )  ;
hplot2 = plot(100*W_gamma(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','\gamma = 1000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'W_gamma_new','.pdf'))

close all;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Simulation with different cost of portfolio adjustment: MU

MU = [900,90000];
gamma = 5;

[z_mu, D_1_mu, D_2_mu, W_mu,R_1_mu, R_2_mu, Q_1_mu, Q_2_mu, K_1_mu, K_2_mu, Y_1_mu, Y_2_mu, CH_1_mu, CH_2_mu] = deal(zeros(hor,length(MU))); 
[a1_mu, a2_mu] = deal(zeros(1,length(MU)));

for i = 1:length(MU)
    mu = MU(i);
    
    a111 = 2*mu/( gamma + (1+beta11)*mu + sqrt( gamma^2 + (1-beta11)^2*mu^2 + 2 * (1+beta11)*gamma*mu) );
    a211 = a111/(mu*sigma2er);
    
    a1_mu(i) = a111;
    a2_mu(i) = a211;

    % simulate model
    dynare GE_mathematics_3645427 noclearall;

    z_mu(:,i) = z_e; % portfolio share
    W_mu(:,i) = W_e; % wealth
    R_1_mu(:,i) = R_1_e; % firm 1 return
    R_2_mu(:,i) = R_2_e; % firm 2 return
    Q_1_mu(:,i) = Q_1_e; % firm 1 asset price
    Q_2_mu(:,i) = Q_2_e; % firm 2 asset price
    K_1_mu(:,i) = K_1_e; % firm 1 capital
    K_2_mu(:,i) = K_2_e; % firm 2 capital
    Y_1_mu(:,i) = Y_1_e; % firm 1 output
    Y_2_mu(:,i) = Y_2_e; % firm 2 output
    D_1_mu(:,i) = D_1_e; % firm 1 dividend
    D_2_mu(:,i) = D_2_e; % firm 2 dividend
    CH_1_mu(:,i) = CH_1_e; % HH 1 consumption
    CH_2_mu(:,i) = CH_2_e; % HH 2 consumption
    
end

%% Figures: MU
fig = figure;
hold on;
hplot1 = plot(100*z_mu(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900' )  ;
hplot2 = plot(100*z_mu(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\mu = 90000');
hplot4 = plot(z_mu(1,1)*zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel('Percentage Points')
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'z_mu_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Q_1_mu(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900'  )  ;
hplot2 = plot(100*Q_1_mu(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\mu = 90000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Q_1_mu_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Q_2_mu(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900'  )  ;
hplot2 = plot(100*Q_2_mu(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\mu = 90000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Q_2_mu_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*K_1_mu(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900'  )  ;
hplot2 = plot(100*K_1_mu(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\mu = 90000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'K_1_mu_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*K_2_mu(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900' )  ;
hplot2 = plot(100*K_2_mu(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\mu = 90000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'K_2_mu_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*R_1_mu(:,1),'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900'  )  ;
hplot2 = plot(100*R_1_mu(:,2),'color', [0.3 0.3 0.3] ,'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\mu = 90000'); 
hplot4 = plot(R_1_mu(1,1)*zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel('Percentage Points');
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'R_1_mu_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*R_2_mu(:,1),'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900'  )  ;
hplot2 = plot(100*R_2_mu(:,2),'color', [0.3 0.3 0.3] ,'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','\mu = 90000'); 
hplot4 = plot(R_1_mu(1,1)*zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel('Percentage Points');
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'R_2_mu_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Y_1_mu(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900' )  ;
hplot2 = plot(100*Y_1_mu(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\mu = 90000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Y_1_mu_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*Y_2_mu(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900' )  ;
hplot2 = plot(100*Y_2_mu(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\mu = 90000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'Y_2_mu_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*D_1_mu(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900' )  ;
hplot2 = plot(100*D_1_mu(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\mu = 90000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'D_1_mu_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*D_2_mu(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900' )  ;
hplot2 = plot(100*D_2_mu(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName', '\mu = 90000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'D_2_mu_new','.pdf'))

fig = figure;
hold on;
hplot1 = plot(100*W_mu(:,1), 'color', [0.0 0.0 0.0] , 'LineWidth', 1.2, 'LineStyle','-', 'DisplayName','\mu = 900' )  ;
hplot2 = plot(100*W_mu(:,2), 'color', [0.3 0.3 0.3] , 'LineWidth', 1.2, 'LineStyle','--' ,'DisplayName','\mu = 90000');
hplot4 = plot(zeros(xxlim,1),'color', black ,'LineWidth',1.0, 'LineStyle',':'); 
ylabel(yylabel);
axis tight; xlim([0 xxlim]); curtick = get(gca, 'xTick'); xticks(unique(round(curtick))); xtickangle(0);
legend([hplot1, hplot2],'location','southeast');
set(gca,'fontsize', 14);
hold off;
set(gcf, 'PaperPosition', [0 0 w h]); %Position plot at left hand corner with width w and height h.
set(gcf, 'PaperSize', [w h]); %Set the paper to have width w and height h.
saveas(gcf,strcat(figpath,'W_mu_new','.pdf'))

close all;
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%