clear 
close all


%data from the excell file
[EXP_RET LABELS]=xlsread('File_excel.xlsx','Mark Infra optim','A2:B12');
COV=xlsread('File_excel.xlsx','Mark Infra optim','H2:R12');
LB1=xlsread('File_excel.xlsx','Mark Infra optim','U2:U12');
UB1=xlsread('File_excel.xlsx','Mark Infra optim','W2:W12');

%setting P and the constraints for positive weights 
P=Portfolio;
P=Portfolio('AssetMean', EXP_RET,'AssetCovar',COV,'Assetlist',LABELS,'LowerBudget', 1, 'UpperBudget', 1);

LB=-zeros(1,length(EXP_RET));
b=-eye(length(EXP_RET));
P = setInequality(P,b,LB);


POSITION = eye(length(EXP_RET))  
GROUP = [1 1 1 1 1 1 0 0 0 0 0;1 1 1 1 1 1 0 0 0 0 0;1 1 1 1 1 1 0 0 0 0 0;1 1 1 1 1 1 0 0 0 0 0;1 1 1 1 1 1 0 0 0 0 0;1 1 1 1 1 1 0 0 0 0 0;0 0 0 0 0 0 1 1 1 1 1;0 0 0 0 0 0 1 1 1 1 1;0 0 0 0 0 0 1 1 1 1 1;0 0 0 0 0 0 1 1 1 1 1;0 0 0 0 0 0 1 1 1 1 1]   
P = setGroupRatio(P, POSITION, GROUP, LB1, UB1);



PORT_WEIGHT=estimateFrontier(P,100)

EXP_RET_INFRA= PORT_WEIGHT'*EXP_RET;
RISK_INFRA=zeros(100,1);

for i = 1 :100
RISK_INFRA(i,1) = sqrt(PORT_WEIGHT(:,i)'*COV*PORT_WEIGHT(:,i));
end 

% Altro modo di calcolare i rend att e rischi dei portafogli
[RISK_INFRA_2, EXP_RET_INFRA_2] = estimatePortMoments(P, PORT_WEIGHT);


[RISKPORT, RETPORT, WEIGHTS]=portopt(EXP_RET,COV,100)




figure(1)
subplot(2,2,[1 2])
scatter(RISK_INFRA, EXP_RET_INFRA, 'o', 'r')
hold on 
scatter(RISKPORT, RETPORT, 'o', 'b')
hold off
title('Infra Group Frontier versus Efficient Frontier')
ylabel('E(R)')
xlabel('Sigma')
grid on

subplot(2,2,3)
area(PORT_WEIGHT')
title('Composition of Infr-Group Portfolios')
ylabel('Weights')
xlabel('Portfolios')
legenda= legend(LABELS,'Location','EastOutside')
ylim([0 1]);
xlim([1 100]);

subplot(2,2,4)
area(WEIGHTS)
title('Composition of Efficient Portfolios')
ylabel('Weights')
xlabel('Portfolios')
legenda= legend(LABELS,'Location','EastOutside')
ylim([0 1]);
xlim([1 100]);


