3D-Plot of a portfolio variance
Show older comments
Hello,
I would like to create a 3D-plot of the variance of a portfolio of two assets.
More precisely, let V denote the (2x2) variance covariance matrix and X denote the (2,1) vector of weights. The portfolio variance is then defined by the following matrix multiplication: X' * V * X
What I want to do is calculate the portfolio variance for all possible Xs, where the elements of X vary from -1 to +2 (-1:0.01:2).
I have already implemented a code:
a1 = [-1:0.01:2].';
a2 = [-1:0.01:2].';
b = zeros(length(a1),length(a1));
for i=1:length(a1);
for j=1:length(a1);
X=[a1(i,1); a2(j,1)];
b(j,i) = X.'*V*X;
end
end
This code runs, but it is computationally too expensive. Any ideas on how to implement this problem in a feasible way?
Thanks.
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!