%	portfolio0_efficient_frontier

%	Matlab program to plot efficient frontier and minimum
%	variance portfolio

bmu = [.08;.03;.05] ;
bOmega = [ .3 .02 .01 ;
	  .02 .15 .03 ;
	  .01 .03 .18 ] ;

bone = ones(length(bmu),1) ;		%	Define vector of ones

ibOmega = inv(bOmega) ;		% Invert Omega - "i" means inverse
A = bone'*ibOmega*bmu ;
B = bmu'*ibOmega*bmu ;
C = bone'*ibOmega*bone ;
D = B*C - A^2 ;
bg = (B*ibOmega*bone - A*ibOmega*bmu)/D ;
bh = (C*ibOmega*bmu - A*ibOmega*bone)/D ;

%	Compute minimum expected return and minimum return SD
gg = bg'*bOmega*bg ;
hh = bh'*bOmega*bh ;
gh = bg'*bOmega*bh ;
mumin = - gh/hh ;
sdmin = sqrt( gg * ( 1 - gh^2/(gg*hh)) ) ;

muP = linspace(min(bmu),max(bmu),50) ;	%	muP grid
sigmaP = zeros(1,50) ;		%	Storage


for i=1:50 ;
	omegaP = bg + muP(i)*bh ;
	sigmaP(i) = sqrt(omegaP'*bOmega*omegaP) ;
end ;

fsize = 16 ;
ind = (muP > mumin) ;	%	Indicates efficient horizon
ind2 = (muP < mumin) ;	%	Indicates locus below efficient horizon

%	Create plot - efficient horizon is shown as a solid curve
%		-  the inefficient part of the locus is dashed
figure(1)
p1 = plot(sigmaP(ind),muP(ind),'-',sigmaP(ind2),muP(ind2),'--' , ...
	sdmin,mumin,'.') ;

%	Change line widths, marker sizes, and colors for better appearance
set(p1(1:2),'linewidth',4) ;
set(p1(1:2),'color','blue') ;
set(p1(3),'markersize',40) ;
set(p1(3),'color','red') ;

%	Label axes
xlabel('standard deviation of return','fontsize',fsize) ;
ylabel('expected return','fontsize',fsize) ;
set(gca,'xlim',[.25, .5]) ;
set(gca,'ylim',[0.028, .08]) ;
grid ;


print portfolio03.ps -deps ;
