Inserting options in plotFrontier function

2 views (last 30 days)
Matlab's Financial toolbox's built in function plotFrontier has two arguments in it: object and weights. Its easy to implement. However, I am trying to change color and style of plot. But it seems harder than I thought. We can use the following simulated data for illustration.
mu=[0.005674, 0.003283 , 0.0003174 , 0.0002323 , 0.0006188, 0.0006223];
sigma=[1.0000 , 0.1541 , 0.1816, 0.0985, 0.1827 , 0.1876;
0.1541 , 1.0000 , 0.2327 , 0.0457 , 0.1485 , 0.2548;
0.1816, 0.2327 , 1.0000 , -0.0017 , 0.2217 , 0.2643;
0.0985 , 0.0457 , -0.0017 , 1.0000 , 0.0539 , 0.0161;
0.1827 , 0.1485 , 0.2217 , 0.0539 , 1.0000 , 0.3191;
0.1876 , 0.2548 , 0.2643 , 0.0161 , 0.3191 , 1.0000];
returns= mvnrnd(mu,sigma,1000);
p=Portfolio;
meanmat=mean(returns);
varmat= cov(returns);
p=Portfolio(p,'assetmean',meanmat,'assetcovar',varmat);
p= Portfolio(p, 'lowerbudget', 1, 'upperbudget', 1);
p= Portfolio(p, 'lowerbound', 0);
wts = estimateFrontier(p, 100);
plotFrontier(p, wts )
I want to change default color and style of the line used in plot. Any help is greatly appreciated.
Thank you in advance.

Accepted Answer

Geoff Hayes
Geoff Hayes on 2 Nov 2014
I don't have the Financial Toolbox, but presumably the result of calling plotFrontier is a figure that you can manipulate after the data has been plotted. Suppose we do the following
figure
hold all
x=linspace(0,2*pi,100);
y=sin(x);
plot(x,y);
plot(x,y+1,'go');
which creates a figure as
So we have two sine curves, one a solid blue line, and the other composed of green circles. We can get the handles to each of these lines which are children of the current axes as
hAxesChildren = get(gca,'Children');
(So gca is a function to get the current axes handle.)
We see that both are lines if we look at their types
get(hAxesChildren,'Type')
ans =
'line'
'line'
The order of elements in hAxesChildren is the reverse in which the elements are added to the axes. So the first line plotted is the last (second) element in the handles array, and the second line plotted is the first element in the handles array.
If we want to change the colour, line style and marker style of the first (solid blue) line, we could do
set(hAxesChildren(2),'Color','r','Marker','o','LineStyle','none');
and if we want to change the same (and line width) for the second curve we could do
set(hAxesChildren(1),'Color','b','LineStyle','-','Marker','none','LineWidth',3);
which will result in
  1 Comment
Ramesh Adhikari
Ramesh Adhikari on 3 Nov 2014
Geoff, you are absolutely right. It does work. Thank you so much for your time and support.

Sign in to comment.

More Answers (0)

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!