Carteras efficientes

function [X, X_Er, X_sigma, Y, Y_Er, Y_sigma, G, G_Er, G_sigma, P_Er, P_sigma] = portfolio(s, r, c0, c1, lambda0, lambda1)
% s is the varcovar matrix and r is the returns
% Student: Edvard Bjarnason
% Professor: Antonio Rivela IE Business School 2010
% Returns and plots the expected return and risk of efficient portfolios
% 2010-03-17
% Example:
% s=[0.10 0.01 0.03 0.05;
% 0.01 0.30 0.06 -0.04;
% 0.03 0.06 0.40 0.02;
% 0.05 -0.04 0.02 0.50;]
% r=[0.06 0.08 0.1 0.15]‘
% c0 and c1 is portfolio constants
% lambda0 and lambda1 is the range of lambda used to plot the graph use
% for example, -2 and 3
% Calculate two efficient portfolios
X=inv(s)*(r-c0)./sum(inv(s)*r-c0);
Y=inv(s)*(r-c1)./sum(inv(s)*(r-c1));

% Calculate return, var and standard deviasions of the two
% portfolios
X_Er=X’*r;
Y_Er=Y’*r;
X_var=X’*s*X;
Y_var=Y’*s*Y;
Y_sigma=sqrt(Y’*s*Y);
X_sigma=sqrt(X’*s*X);
XY_cov=X’*s*Y;

% Calculate the minimum variance portfolios
G=[1 1 1 1]*inv(s)/sum([1 1 1 1]*inv(s));
G_Er=G*r;
G_var=G*s*G’;
G_sigma=sqrt(G_var’);

% Make linear combinations of the two portfolios
lambda=[lambda0:0.01:lambda1];
P_Er=(lambda*X_Er+(1-lambda)*Y_Er)’;
P_var=(lambda’*X_sigma).^2+((1-lambda)’*Y_sigma).^2+2*lambda’.*(1-lambda)’*XY_cov;
P_sigma=sqrt(P_var);
plot(P_sigma,P_Er);
xlabel ‘risk’;
ylabel ‘return’;
end

Septiembre 2010
L M X J V S D
« Jul    
 12345
6789101112
13141516171819
20212223242526
27282930