% Computer Lab 8 Solutions %----------------------------------------------------------------- % Q1(a) load S_rio_m.txt load asx200_m.txt % Percentage monthly returns: len=length(S_rio_m); R_rio_m = 100*(S_rio_m(1:len-1)-S_rio_m(2:len))./S_rio_m(2:len); len=length(asx200_m); R_asx200_m = 100*(asx200_m(1:len-1)-asx200_m(2:len))./asx200_m(2:len); % Q1(b) mu_rio=mean(R_rio_m) mu_asx200=mean(R_asx200_m) cov_rio_asx200=cov(R_rio_m,R_asx200_m) beta=cov_rio_asx200(1,2)/cov_rio_asx200(2,2) alpha=mu_rio-beta*mu_asx200 % Q1(c) figure(1) set(gcf,'PaperType','A4') plot(R_asx200_m,R_rio_m,'o') xlabel('ASX200 % Monthly Return') ylabel('Rio % Monthly Return') % Plot rio's asx200 characteristic line: x_lo=min(R_asx200_m); x_hi=max(R_asx200_m) x=linspace(x_lo,x_hi,101); y=alpha+beta*x; hold on plot(x,y,'m') title('RioTinto Characteristic Line') % Q1(d) load S_nab_m.txt % Percentage monthly return: len=length(S_nab_m); R_nab_m = 100*(S_nab_m(1:len-1)-S_nab_m(2:len))./S_nab_m(2:len); mu_nab=mean(R_nab_m) cov_nab_asx200=cov(R_nab_m,R_asx200_m) beta=cov_nab_asx200(1,2)/cov_nab_asx200(2,2) alpha=mu_nab-beta*mu_asx200 figure(2) set(gcf,'PaperType','A4') plot(R_asx200_m,R_nab_m,'o') xlabel('ASX200 % Monthly Return') ylabel('NAB % Monthly Return') % Plot nab's asx200 characteristic line: y=alpha+beta*x; hold on plot(x,y,'m') title('NAB Characteristic Line') %----------------------------------------------------------------- % Question 2 % We use the portfolio equations directly to answer this question. r=[10 15]'; s=sqrt([8 12])'; C=[1 0.5 ; 0.5 1]; rho=0.5; % Part (a): S=diag(s)*C*diag(s) % Part (b): figure(3) set(gcf,'PaperType','A4') clf x1=-1:.01:2; x2=1-x1; x=[x1;x2]; mu=10*x1+15*x2; sigma=[]; % Clear or empty an array, in this case sigma, when constructing it element by element. for i=1:length(x1) sigma(i)=sqrt(x(:,i)'*S*x(:,i)); end hold off plot(sigma,mu) title('Q3') xlabel('\sigma') ylabel('\mu') hold on % Part (c): x1=0:.01:1; x2=1-x1; x=[x1;x2]; mu=10*x1+15*x2; sigma=[]; % Clear or empty an array, in this case sigma, when constructing it element by element. for i=1:length(x1) sigma(i)=sqrt(x(:,i)'*S*x(:,i)); end plot(sigma,mu,'r','linewidth',2) plot(s(1),r(1),'o') text(s(1),r(1)-2,'P_1') plot(s(2),r(2),'o') text(s(2),r(2)-3,'P_2') % Part (d): t=0.5; for i=1:5 Z=-2*i; sigma=0:.1:7; mu=(0.5*sigma.^2-Z)/t; plot(sigma,mu,'g') if Z==-2, text(sigma(11),mu(11),'Z=-2'),end if Z==-10, text(sigma(11),mu(11),'Z=-10'),end end %----------------------------------------------------------------- % Question 3 % We use the portfolio equations directly to answer this question. % Part (a): figure(4) set(gcf,'PaperType','A4') clf x1=0:.01:1; x2=1-x1; x=[x1;x2]; mu=10*x1+15*x2; sigma=[]; % Clear or empty an array, in this case sigma, when constructing it element by element. for i=1:length(x1) sigma(i)=sqrt(x(:,i)'*S*x(:,i)); end hold on plot(sigma,mu,'b') title('Q4') xlabel('\sigma') ylabel('\mu') hold on % Part (b): x_o=(s(2)^2-rho*s(1)*s(2))/(s(1)^2+s(2)^2-2*rho*s(1)*s(2)); % Minimum risk x. x1=0:.01:x_o; x2=1-x1; x=[x1;x2]; mu=10*x1+15*x2; sigma=[]; % Clear or empty an array, in this case sigma, when constructing it element by element. for i=1:length(x1) sigma(i)=sqrt(x(:,i)'*S*x(:,i)); end plot(sigma,mu,'r','linewidth',2) % Part (c) (no shorting): % Minimum risk portfolio: mu_o=10*x_o+15*(1-x_o); sigma_o=sqrt([x_o,1-x_o]*S*[x_o,1-x_o]'); plot(sigma_o,mu_o,'o') text(sigma_o+0.05,mu_o,'Minimum risk portfolio') % Maximum risk portfolio: x=0; mu=10*x+15*(1-x); sigma=sqrt([x,1-x]*S*[x,1-x]'); plot(sigma,mu,'o') text(sigma-0.3,mu,'Maximum risk portfolio') % Minimum return portfolio: x=1; mu=10*x+15*(1-x); sigma=sqrt([x,1-x]*S*[x,1-x]'); plot(sigma,mu,'o') text(sigma,mu+0.3,'Minimum return portfolio') % Part (d): t=0.5; x=(t*(r(1)-r(2))+s(2)^2-rho*s(1)*s(2))/(s(1)^2+s(2)^2-2*rho*s(1)*s(2)); % Minimum risk x. mu=10*x+15*(1-x); sigma=sqrt([x,1-x]*S*[x,1-x]'); plot(sigma,mu,'o') text(sigma+0.05,mu,'Optimum portfolio') Z=-mu*t+sigma^2/2; sigma=2.6:0.01:3.5; mu=(0.5*sigma.^2-Z)/t; plot(sigma,mu,'g') text(3.1,16,[ 'Optimum level contour Z=' num2str(Z)])