In my code I want to find all the weight, Return and Risk for my portfolio but for loop give me only last result and 'disp()' function is not enough for all the result Here is my code
z = 100;
percent_change = 1;
n = (z/percent_change)+1;
a = (0:percent_change:z);
b = (0:percent_change:z);
c = (0:percent_change:z);
d = (0:percent_change:z);
for i = 1:(z/percent_change)+1
for j = 1:(z/percent_change)+1
for k = 1:(z/percent_change)+1
for l = 1:(z/percent_change)+1
if a(i)+b(j)+c(k)+d(l) == z
p = Portfolio('assetmean', m, 'assetcovar', C, 'lowerbudget', 1, 'upperbudget', 1, 'lowerbound', zeros(size(m)));
p = setDefaultConstraints(p);
pwgt = [a(i); b(j); c(k);d(l)];
[prsk,pret] = estimatePortMoments(p, pwgt);
disp(pwgt);
disp([prsk,pret]);
end
end
end
end
end
Actually I want all the possible portfolio to create frontier ( not just half of it) I'm just started to use matlab for a few months so any tips would really help me. Thankyou

 채택된 답변

dpb
dpb 2016년 11월 14일

0 개 추천

Simply subscript (preallocate to save reallocation dynamically) the desired output variables...
...
ix=0; % index for cases
for i = 1:n
for j = 1:n
for k = 1:n
for l = 1:n
if a(i)+b(j)+c(k)+d(l) == z
ix=ix+1; % increment the counter
p = Portfolio('assetmean', m, 'assetcovar', C, ...
'lowerbudget', 1, 'upperbudget', 1, ...
'lowerbound', zeros(size(m)));
p = setDefaultConstraints(p);
pwgt{ix} = [a(i); b(j); c(k);d(l)];
[prsk{ix},pret{ix}] = estimatePortMoments(p, pwgt);
...
I don't know anything about what the Financial Toolbox function actually returns but appears to be combination of vectors/arrays possible; hence the outputs are cell arrays containing those elements...
Wonder if there aren't builtin methods to acquire the desired results from the portfolio object itself, though????

댓글 수: 2

It has just for efficient portfolio but not for all possible portfolio Thankyou for your help It's not work for [prsk{ix},pret{ix}] = estimatePortMoments(p, pwgt); but I think I can adapt on your answer
dpb
dpb 2016년 11월 15일
편집: dpb 2016년 11월 15일
Yeah, can't concatenate cells into vector via the [] notation...put the combined into a cell array element.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Big Data Processing에 대해 자세히 알아보기

질문:

2016년 11월 14일

편집:

dpb
2016년 11월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by