Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

using linear equality constraint within the loop

1 visualización (últimos 30 días)
Sameer
Sameer el 30 de Mayo de 2014
Comentada: Sameer el 30 de Mayo de 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.
Thanks.
  5 comentarios
Geoff Hayes
Geoff Hayes el 30 de Mayo de 2014
Editada: Geoff Hayes el 30 de Mayo de 2014
Sameer - you should be able to just edit your original question and modify the text there, rather than posting a new comment. The above comment is only somewhat easier to read but has not been formatted as per the link. Just highlight the portion of the text that is code and then press the {} Code button.
And you've posted different code too! Why?
Sameer
Sameer el 30 de Mayo de 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.

Respuestas (0)

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by