필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

using linear equality constraint within the loop

조회 수: 1 (최근 30일)
Sameer
Sameer 2014년 5월 30일
댓글: Sameer 2014년 5월 30일
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
Geoff Hayes
Geoff Hayes 2014년 5월 30일
편집: Geoff Hayes 2014년 5월 30일
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 2014년 5월 30일
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.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by