how to store values in matrix from for loop?
显示 更早的评论
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
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Big Data Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!