How do I generate all possible weights for a constraint

4 views (last 30 days)
While I was working on my portfolio optimization I wanted to perform a numerical analysis and I wanted to generate several combinations of weights that all sum to 1. in the case of 3 assets I had this code:
for i= 0:0.1:1 for j = 0:0.1:(1-i) w_Consmr = i; w_Manuf = j; w_HiTec = 1-j-i; a = a+1; w(a,:) = [w_Consmr w_Manuf w_HiTec] ; end end
However, now I want to do this for lets say, 50 assets and making 50 for loops seems quite cumbersome, is there another way to make this more efficient ?
Sincerely, Stephan
  3 Comments
Matt J
Matt J on 11 Apr 2013
Edited: Matt J on 11 Apr 2013
What do you mean by "several"? For 50 assets, the number of combinations can be intractably large, depending on whether you'd still be using increments of 0.1 or something else. If 0.1, then at most 10 of the weights can be non-zero. Is that what you want?
stef
stef on 11 Apr 2013
What I wanted to try to do is to have all possible combinations for my weights under those restrictions. I already knew that in this exact way the amount of combinations would take too much time to compute and thus I was wondering if there was a different and more efficient algorithm to this approach, but after some more thinking and searching I think this would be the only way to do it, other than just randomizing weights.
So I think I will just use random weights as you proposed since it would indeed be too big to compute the weights for 50 assets this way
Thank you for your time and help.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 11 Apr 2013
Why not do something like the following?
w=rand(1,50);
w=w/sum(w);

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!