Efficient Frontier code error
1 view (last 30 days)
Show older comments
Hi, I am running the following code I found:
% portfolio0_efficient_frontier % Matlab program to plot efficient frontier and minimum % variance portfolio bmu = [.08;.03;.05] ; bOmega = [ .3 .02 .01 ; .02 .15 .03 ; .01 .03 .18 ] ; bone = ones(length(bmu),1) ; % Define vector of ones ibOmega = inv(bOmega) ; % Invert Omega ‐ "i" means inverse A = bone'*ibOmega*bmu ; B = bmu'*ibOmega*bmu ; C = bone'*ibOmega*bone ; D = B*C - A^2 ; bg = (B*ibOmega*bone - A*ibOmega*bmu)/D ; bh = (C*ibOmega*bmu - A*ibOmega*bone)/D ; % Compute minimum expected return and minimum return SD gg = bg'*bOmega*bg ; hh = bh'*bOmega*bh ; gh = bg'*bOmega*bh ; mumin = - gh/hh ; sdmin = sqrt( gg * ( 1 - gh^2/(gg*hh)) ) ; muP = linspace(min(bmu),max(bmu),50) ; % muP grid sigmaP = zeros(1,50) ; % Storage for i=1:50 ; omegaP = bg + muP(i)*bh ; sigmaP(i) = sqrt(omegaP'*bOmega*omegaP) ; end ; fsize = 16 ; ind = (muP > mumin) ; % Indicates efficient horizon ind2 = (muP < mumin) ; % Indicates locus below efficient horizon % Create plot ‐ efficient horizon is shown as a solid curve % ‐ the inefficient part of the locus is dashed figure(1) p1 = plot(sigmaP(ind),muP(ind),'-',sigmaP(ind2),muP(ind2),'--',sdmin,mumin,'.') ; % Change line widths, marker sizes, and colors for better appearance set(p1(1:2),'linewidth',4) ; set(p1(1:2),'color','blue') ; set(p1(3),'markersize',40) ; set(p1(3),'color','red') ; % Label axes xlabel('standard deviation of return','fontsize',fsize) ; ylabel('expected return','fontsize',fsize) ; set(gca,'xlim',[.25, .5]) ; set(gca,'ylim',[0.028, .08]) ; grid ; print portfolio03.ps - deps ;
And get the following error:
Attempted to access cur_arg(2); index out of bounds because numel(cur_arg)=1.
Error in checkArgsForHandleToPrint (line 40)
Error in print>LocalCreatePrintJob (line 336) handles = checkArgsForHandleToPrint(0, varargin{:});
Error in print (line 153) [pj, inputargs] = LocalCreatePrintJob(varargin{:});
Error in testefronteiraef (line 46) print portfolio03.ps - deps ;
What can I do?
Thank you very much
0 Comments
Accepted Answer
David Sanchez
on 12 May 2015
Watch the last line of code:
print portfolio03.ps - deps ;
Mind the blank space right before deps
simply delete it:
print portfolio03.ps -deps
More Answers (0)
See Also
Categories
Find more on Portfolio Optimization and Asset Allocation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!