Sei sulla pagina 1di 4

load C:\Users\anamika.balodi\Documents\MATLAB\HW2\Indu10_July26_July11.

dat;
load C:\Users\anamika.balodi\Documents\MATLAB\HW2\Factors_July26_July11.dat;
T=1021;
N=10;
tau = 3;
bill=Factors_July26_July11(1:T,5) / 100;
R_10=Indu10_July26_July11(1:T,2:11) / 100;
R_10_ex=R_10 - bill*ones(1,N);
excess of the T-bill

mu=mean(R_10_ex);
mu=mu';
V=cov(R_10_ex);

T-bill return
% the 10 industry returns
% industry returns in

% mean of 10 industry assets


% making it a column vector
%covariance of 10 assets

%%%
Portfolio constraints %%%
a=zeros(N,1);
% letting a_i=0 for all i, i.e., no short sells
b=0.3*ones(N,1);
%
b_i=0.5, no more than 50% of money invested into one
asset
% a=-0.1*ones(N,1);
%%%%%%%%%% Computing the optimal weight on the N risky aasets based on Arnold
Neumaier's quadratic proramming routine: MINQ
%
%
min
fct = gam + c^T x + 0.5 x^T G x
%
%
s.t.
x in [xu,xo]
% xu<=xo is assumed
% where G is a symmetric n x n matrix, not necessarily
definite
% Note!!!:
if you have Matlab' Optimization Toolbox, you can use its
%
quadprog instead, with
[x,fval,exitflag]=QUADPROG(G,c,[],[],[],[],xu,xo,xx);
gam=0;
c=-mu;
G=tau*V;
xu=a;
xo=b;
xx=ones(N,1)/N;
the equal-weighted

% search the optimal portfolio weights starting from

prt=0;
[x,fct,ier,nsub]=quadprog(gam,c,G,xu,xo,prt,xx);
% calling the
minimization program to get the minimized value and the associated x

w_1=x;
constraints

% an N-vector of the optimal weights subject to the

w0=(1/tau)*V^(-1)*mu;
(174)

% the optimal unconstrained weights, equation

% Compute the Sharpe ratio of the constrained port, etc, with hindsight
and ignore transaction costs
Port_1=zeros(T,1);
portfolio
PortS=zeros(T,1);

% define this T vector to store the returns on the


% to store the accumulative returns

Port_1(1)=bill(1)+w_1'*ReEX(1,:)';
period

% return in the first


% notice that

ReEX(1,:)

is

the 1st row, the traspose makes it a column


PortS(1)=1+Port_1(1);
for t=2:T,
Port_1(t)=bill(t) + w_1'*ReEX(t,:)';
PortS(t)=PortS(t-1)*(1+Port_1(t));
t
end;
PortEX_1=Port_1 - bill;
muP_1=mean(PortEX_1);
sig2P_1=var(PortEX_1);
SharpeP_1=muP_1 / sqrt(sig2P_1);

% return at t
% accumulativ return at

% the portfolio excess returns

% Compute the Sharpe ratio of the unconstrained port, etc, with


hindsight and ignore transaction costs
Port0=zeros(T,1);
portfolio
PortS0=zeros(T,1);

% define this T vector to store the returns on the


% to store the accumulative returns

Port0(1)=bill(1)+w0'*ReEX(1,:)';

% return in the first period

PortS0(1)=1+Port0(1);
for t=2:T,
Port0(t)=bill(t) + w0'*ReEX(t,:)';
PortS0(t)=PortS0(t-1)*(1+Port0(t));
at t
end;
Port0EX=Port0 - bill;
muP0=mean(Port0EX);
sig2P0=var(Port0EX);
SharpeP0=muP0 / sqrt(sig2P0);

% return at t
% accumulativ return

% the portfolio excess returns

% Compute Sharpe Ratio and the accumulative return on the mkt


RmEX_1=Factors_July26_July11(1:T,2) / 100;
% Get the returns on mkt in
excess of T-bill rate, the data are such a way
mu_ex1=mean(RmEX_1);
% estimate the mean and variance of the mkt
excess return
sigex_1=var(RmEX_1);
SharpeRM_ex1=mu_ex1/sqrt(sigex_1);
% Sharpe ratio of the mkt

Rm_01=RmEX_1 + bill;
adding back the riskfree rate
CC_RM_01=zeros(T,1);
CC_RM_01(1)=1+Rm_01(1);
first month
for t=2:T,
CC_RM_01(t)=CC_RM_01(t-1)*(1+Rm_01(t));
t
end;

fprintf('******

% mkt return, obtained by


%

accumulativ return in the


% accumulativ return at

risk aevrsion ********** \n');

tau
fprintf('****** weights on the risky assets: constrained and unconstrained
ones ********** \n');
[w_1,w0]

fprintf('****** weights on the riskfree asset in the constrained and


unconstrained cases ********** \n');
[(1-w_1'*ones(N,1)), (1-w0'*ones(N,1))]
fprintf('****** Mean, std abd Sharpe ratios of the mkt, and the constrained
and un-c* portfolios ********** \n');
A1=[mu_ex1 sqrt(sigex_1) SharpeRM_ex1]';
A2=[muP_1 sqrt(sig2P_1) SharpeP_1]';
A3=[muP0 sqrt(sig2P0) SharpeP0]';
[A1 A2 A3]
fprintf('******

max, min return of the mkt and the port

********** \n');

B1=[max(Rm_01) min(Rm_01)]';
B2=[max(Port_1) min(Port_1)]';
B3=[max(Port0) min(Port0)]';
[B1 B2 B3]
fprintf('****** Accu return of the mkt, constrained and un-c* the ports
********** \n');
CC_RM_01(T)
PortS(T)
PortS0(T)

fprintf('******

Plot of the accu returns

********** \n');

PP=[CC_RM_01 PortS PortS0];


plot(PP)

Potrebbero piacerti anche