Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Getting Started with Portfolio Optimization -- Video Tutiroal

Subject: Getting Started with Portfolio Optimization -- Video Tutiroal

From: Ryan

Date: 4 Nov, 2012 00:09:09

Message: 1 of 2

Does anyone have the full code for this video tutorial?
http://www.mathworks.com/videos/getting-started-with-portfolio-optimization-68762.html

I followed along with the presenter, and typed out all the code that I saw on the screen, but I think he skips around too much, or something; my code is NOT compiling and running like his is. For whatever reason, I’m not getting the results that the instructor is getting. Below is my 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 13 27]) = 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([15, 18]) = 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([10, 20, 21]) = 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(0.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.03*ones(1,30);
 
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);
 
 
The very first error that I get is right here:
Subscripted assignment dimension mismatch.

Error in Portfolio_Optimization (line 12)
ClosePrice(:,i) = temp(:,2);


AS FAR AS I KNOW, I'M DOING THIS EXACTLY THE SAME AS THE PRESENTER IN THE VIDEO!!!

Can someone please tell me what I’m missing here??? Or, can someone show me a link where I can download the full sample code???

Thanks!!!

Subject: Getting Started with Portfolio Optimization -- Video Tutiroal

From: Steven_Lord

Date: 5 Nov, 2012 15:26:40

Message: 2 of 2



"Ryan " <ryanshuell@gmail.com> wrote in message
news:k74bn5$hls$1@newscl01ah.mathworks.com...
> Does anyone have the full code for this video tutorial?
> http://www.mathworks.com/videos/getting-started-with-portfolio-optimization-68762.html

I don't see it on the MATLAB Central File Exchange. Please contact Customer
Service and ask if they can provide you with the source code for that
webinar.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us