Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Question About Portfolio Optimization Code
Date: Fri, 12 Oct 2012 02:22:08 +0000 (UTC)
Organization: HSBC
Lines: 124
Message-ID: <k57usg$pla$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1350008528 26282 172.30.248.38 (12 Oct 2012 02:22:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 12 Oct 2012 02:22:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2921053
Xref: news.mathworks.com comp.soft-sys.matlab:780497

Can someone please tell me what is wrong with this code?

c = yahoo

ticker = {'MMM', 'AA', 'AXP', 'T', 'BAC', 'BA', 'CAT', 'CVX', 'CSCO', 'KO', 'DD' ...
	'XOM', 'GE', 'HPQ', 'HD', 'INTC', 'IBM', 'JPM', 'JNJ', 'KFT', 'MCD', 'MRK' ...
	'MSFT', 'PFE', 'PG', 'TRV', 'UTX', 'VZ', 'WMT', 'DIS'}

for i = 1:30

Price.(ticker{i}) = fetch(c,ticker(i),'Adj Close','01/01/2000','12/31/2010','m');
temp = Price.(ticker{i});
ClosePrice(:,i) = temp(:,2);
end



Returns = price2ret(ClosePrice);


plot(Returns(:,1:2));
ylabel('Monthly Return');
xlabel('Month');
legend('3M', 'Alcoa');
title('3M vs Alcoa Monthly Returns')

p = (Portfolio('Name', 'DJIA 30'));
p = p.setAssetList(ticker);
disp(p);

p = p.estimateAssetMoments(Returns);
p = p.setDefaultConstraints;

[prisk, preturns] = p.plotFrontier(10);
[pwvt] = p.estimateFrontier(10);
hold on
plot(prisk, preturns, 'ored');
format_plots();


A = zeros(size(ticker));
A([1 2 3]) = 1;
b = .1;


p = p.setEquality(A, b);

p = Portfolio(p,'AEquality', A, 'bEquality', b);

hold on
p.plotFrontier;
format_plots();


C = zeros(size(ticker));
C([4, 5]) = 1;
d = .05;


p = p.setInequality(C,d);


p = Portfolio(p, 'AInequality', C, 'bInequality', d);

hold on
p.plotFrontier;
format plots();

G = zeros(size(ticker));
G([4, 5]) = 1;

p = p.setGroups(G, 0.1, 0.5);

p = Portfolio(p, 'GroupMarix', G, 'LowerGroup', 0.1, 'UpperGroup', 0.5);

hold on
p.plotFrontier;

lb = -.05;
ub = 0.10;


p = p.setBounds(lb,ub);


p = Portfolio(p, 'LowerBound', lb, 'UpperBound', ub);

hold on
p.plotFrontier;
format_plots();


p = p.setBudget(.95, 1.05);
p = portfolio(p, 'LowerBudget', .95, 'UpperBudget', 1.05);

hold on
p.plotFrontier;
format_plots();

p = portfolio(p, 'RiskFreeRate', .01);
bc = 0.005;
sc = 0.007;
X_o = 0.20*ones(1,5);

p = p.setInitPort(X_o);
p = p.setCosts(bc,sc);


[pwgt, pbuy, psell] = p.estimateFrontier (4);

q = p;
p = Portfolio(p, 'BuyCost', 0, 'SellCost', 0);



I copied the code form the video here:
http://www.mathworks.com/videos/getting-started-with-portfolio-optimization-68762.html

I didn’t see any place to download the original source code; I just typed it out as the instructor was going through it.  I could have missed a couple of lines; not sure.  

Can someone please step through the code and help me get it straightened out?  I’m doing this simply as a learning example, and I’m getting some errors that are so weird that I can’t even explain them.

Thanks everyone!!
Ryan--