clear all
close all



% Inputs trasferred on Matlab
[EXP_RET LABELS]=xlsread('File_excel.xlsx','Resampling_TM','A2:B12')
COV=xlsread('File_excel.xlsx','Resampling_TM','G2:Q12')


[ASSET NNN]=size(COV);
SIZE=xlsread('File_excel.xlsx','Resampling_TM','A17');

SIM=xlsread('File_excel.xlsx','Resampling_TM','A14');



% frontiera efficiente semplice
[RISK2,ROR2,WTS2]=portopt(EXP_RET,COV,100);



STORE_WTS=zeros(100,ASSET,SIM);  




for i = 1:SIM
i
SIM_RET= mvnrnd(EXP_RET, COV,SIZE);
EXP_RET_SIM=mean(SIM_RET);
COV_SIM=cov(SIM_RET);

[RISK,ROR,WTS]=portopt(EXP_RET_SIM,COV_SIM,100);

if i<=25
figure(1)
subplot(5,5,i)
area(WTS)
ylim([0 1]);
xlim([1 100]);
pause

end

STORE_WTS(:,:,i)= WTS;
end 


RESAPL_WEIGHTS=mean(STORE_WTS,3);



EXP_RET_RESAMPL= RESAPL_WEIGHTS*EXP_RET;

RISK_RESAMPL = zeros(100,1);

for i = 1 :100
RISK_RESAMPL(i,1) = sqrt(RESAPL_WEIGHTS(i,:)*COV*RESAPL_WEIGHTS(i,:)');
end 


figure(2)
subplot(2,2,[1 2])
plot (RISK2,ROR2,'R')
hold on 
plot (RISK_RESAMPL,EXP_RET_RESAMPL,'B')
hold off
title('Efficient Frontier versus Resampled Frontier')
legenda= legend({'Eff Front','RESAMPLED Front'},'Location','SouthOutside')

subplot(2,2,3)
area(WTS2)
legenda= legend(LABELS,'Location','EastOutside')
title('Composition of Efficient Portfolios')
ylim([0 1]);
xlim([1 100]);
subplot(2,2,4)
area(RESAPL_WEIGHTS)
legenda= legend(LABELS,'Location','EastOutside')
title('Composition of Resampled Portfolios')
ylim([0 1]);
xlim([1 100]);





