This question is closed. Reopen it to edit or answer.

using linear equality constraint within the loop

1 view (last 30 days)
Sameer on 30 May 2014
Commented: Sameer on 30 May 2014
My assignment is to optimize a portfolio given a set of stock.
I already have one linear equality constraint that makes certain stocks sum to a certain amount of weight in the portfolio.
However, I also have to put two additional constraints to the portfolio that makes the total sum of the weights equal to sum (in the vector W) which is a row vector it is written as sum(W) = 1.00
. and the portfolio return has to equal a specific number that the current iteration is using in the loop.
it is written as ERMean*W' = ERGrid(1,i); (it is inside the loop).
for the minization, I am using "fmincon" that already has linear equality constraints
but my professor said these two constraints that I explained "hardcoded within the loop". I am confused as to what he is saying.
here is how the code looks:
i=1; while i<=cols(ERGrid); ERMean*W' = ERGrid(1,i); sum(W) = 1.00; [W] = fmincon('objfun',x0,swtOther_A,swtOther_b,swtOther_Aeq,swtOther_beq,swtMinWt1,swtMaxWt1,[],options); ERGrid(2:swtN+1,i) = W; i=i+1; end;
But it gives me error when running the ERMean and sum(W) lines in the loop. For the ERMean line it is saying: "The expression to the left of the equals sign is not a valid target for an assignment."
For the sum(W) line it is saying: "Subscript indices must either be real positive integers or logicals."
Can someone PLEASE help me on this issue? I have been struggling with it for a while.
Sameer on 30 May 2014
I figured it out, but now I am have trouble with a different problem:
the discussion is here, if you would like to look at it.

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by