%	1 = MSCI Hong Kong	
%	2 = MSCI Singapore	
%	3 = MSCI Brazil	
%	4 = MSCI Argentina	
%	5 = MSCI UK	
%	6 = MSCI Germany	
%	7 = MSCI Canada	
%	8 = MCSI France	
%	9 = MCSI Japan	
%	10 = S&P 500	

%	Monthly data, Jan 1988 to Jan 2002

load countries.dat ;
[n,m] = size(countries) ;
price = countries(:,4:m) ;



log_retn = diff(log(price)) ;
bmu_true = mean(log_retn)' ;
N = length(bmu_true) ;

bOmega_true = cov(log_retn) ;
ibOmega_true = inv(bOmega_true) ;
fsize = 10 ;
ngrid = 100 ;
muP = linspace(0,.03,ngrid)'  ;%	Grid of muP values
rand('seed',55393775) ;

for iter = 1:6 ;

select = ceil((n-1)*rand(n-1,1)) ;
log_retn_boot = log_retn(select,:) ;

bmu_boot = mean(log_retn_boot)' ;
bOmega_boot = cov(log_retn_boot) ;


bone = ones(N,1) ;


%	Compute minimum expected return and minimum return SD
ibOmega_boot = inv(bOmega_boot) ;	% Invert Omega - "i" means inverse

A_boot = bone'*ibOmega_boot*bmu_boot ;
B_boot = bmu_boot'*ibOmega_boot*bmu_boot ;
C_boot = bone'*ibOmega_boot*bone ;
D_boot = B_boot*C_boot - A_boot^2 ;
bg_boot = (B_boot*ibOmega_boot*bone - A_boot*ibOmega_boot*bmu_boot)/D_boot ;
bh_boot = (C_boot*ibOmega_boot*bmu_boot - A_boot*ibOmega_boot*bone)/D_boot ;
gg_boot = bg_boot'*bOmega_boot*bg_boot ;
hh_boot = bh_boot'*bOmega_boot*bh_boot ;
gh_boot = bg_boot'*bOmega_boot*bh_boot ;

A_true = bone'*ibOmega_true*bmu_true ;
B_true = bmu_true'*ibOmega_true*bmu_true ;
C_true = bone'*ibOmega_true*bone ;
D_true = B_true*C_true - A_true^2 ;
bg_true = (B_true*ibOmega_true*bone - A_true*ibOmega_true*bmu_true)/D_true ;
bh_true = (C_true*ibOmega_true*bmu_true - A_true*ibOmega_true*bone)/D_true ;
gg_true = bg_true'*bOmega_true*bg_true ;
hh_true = bh_true'*bOmega_true*bh_true ;
gh_true = bg_true'*bOmega_true*bh_true ;

sigmaP_true = zeros(ngrid,1) ;	%	Set up storage
sigmaP_opt = zeros(ngrid,1) ;
muP_boot    = zeros(ngrid,1) ;
omegaP_boot = zeros(N,ngrid) ;
omegaP_opt =  zeros(N,ngrid) ;

for i = 1:ngrid ;

omegaP_boot(:,i) =  bg_boot + muP(i)*bh_boot ;
omegaP_opt(:,i) =  bg_true + muP(i)*bh_true ;
sigmaP_boot(i) = sqrt(omegaP_boot(:,i)'*bOmega_boot*omegaP_boot(:,i)) ;
sigmaP_opt(i) = sqrt(omegaP_opt(:,i)'*bOmega_true*omegaP_opt(:,i)) ;
sigmaP_true(i) = sqrt(omegaP_boot(:,i)'*bOmega_true*omegaP_boot(:,i)) ;
muP_boot(i) = bmu_true'*omegaP_boot(:,i) ;
end ;

subplot(3,2,iter) ;

p = plot(sigmaP_true,muP_boot,'--', ...
	sigmaP_opt,muP) ;
set(p(1),'color','red') ;
set(p(2),'color','blue') ;
set(p(1),'linewidth',5) ;
set(p(2),'linewidth',5) ;
l=legend('achieved','optimal',2) ;
set(gca,'fontsize',fsize) ;
set(l,'fontsize',fsize) ;
xlabel('standard deviation of return (\sigma_P)','fontsize',fsize) ;
ylabel('expected return (\mu_P)','fontsize',fsize) ;
set(gca,'ylim',[.007,.018]) ;
set(gca,'xlim',[0.03,.055]) ;

end ;

orient tall ;
print count_all02.ps -deps ;
