clear all
clc

load Approx_10.mat;

per=840; %number of simulated month
lev=2; %financial leverage
n=100; %number of simulations


shocks = zeros(2,per)./0; % put NaNs everywhere
r=zeros(28,per,n);
% levexr=zeros(per,n);
% y=zeros(per,n);
% ret_a=zeros(n,1);
% output=zeros(n,7);

for i=1:n
r(:,:,i)=dynare_simul('Approx_10.mat', shocks);
end

%Levered excess return on equity
for i=1:n
levexr(:,i)=lev*r(dyn_i_exr,:,i)'+normrnd(0,1,per,1)*((.065)/sqrt(12));
ret_a(i)=mean(sum(reshape(levexr(:,i),[12,(per)/12])));
sret_a(i)=std(sum(reshape(levexr(:,i),[12,(per)/12])));
rf(:,i)=(exp(r(dyn_i_rf,:,i))-1)';
rf_a(i)=mean(sum(reshape(rf(:,i),[12,(per)/12])));
srf_a(i)=std(sum(reshape(rf(:,i),[12,(per)/12])));
y(:,i)=r(dyn_i_dy,:,i)';
sy_a(i)=std(sum(reshape(y(:,i),[12,(per)/12])));
c(:,i)=r(dyn_i_dc,:,i)';
sc_a(i)=std(sum(reshape(c(:,i),[12,(per)/12])));
inv(:,i)=r(dyn_i_di,:,i)';
sinv_a(i)=std(sum(reshape(inv(:,i),[12,(per)/12])));
end
output(:,1)=(exp(ret_a)-1)*100;
output(:,2)=(sret_a)*100;
output(:,3)=((rf_a))*100;
output(:,4)=srf_a*100;
output(:,5)=(sy_a)*100;
output(:,6)=(sc_a)./(sy_a);
output(:,7)=(sinv_a)./(sy_a);

% 
% levexr=lev*sim_res(dyn_i_exr,:)'+normrnd(0,1,per,1)*((.065)/sqrt(12)); %levered monthly log-excess return is
% ret=exp(levexr)-1; %transformation from logs to levels
% ret_a = sum(reshape(ret,[12,(per)/12])); %annualized equity premium
% EP=mean(ret_a)*100; %Mean equity premium
% SEP=std(ret_a)*100;
% 
% rf=exp(sim_res(dyn_i_rf,:))-1;
% rf_a=sum(reshape(rf,[12,(per)/12])); %annualized risk free rate
% RF=mean(rf_a)*100; %Mean risk free rate
% SRF=std(rf_a)*100;
