필터 지우기
필터 지우기

Nested for loop portfolio optimization

조회 수: 1 (최근 30일)
Kevin van Berkel
Kevin van Berkel 2013년 5월 2일
Hi guys,
I am probably doing something utterly silly which holds me back from retrieving the desired results.
I have two matrices: Matrix(A), which is a vector containing returns from three risky assets, and Matrix C, which consists of optimally genereated weights of those risky assets. To obtain the return, I wrote the following loop:
for i = 1:155
for j = 1:155
returns = A(i,:)*C(j,:)'
end
end
This code yields a 1x155 matrix, exactly as I asked for, But, the answers are not correct.
Does anyone have a clue what I do wrong here?
Thanks for the effort!
Cheers,
Kevin
  댓글 수: 2
Matt J
Matt J 2013년 5월 2일
The code you've shown returns a scalar, not a 1x155 vector. You should show us the code you're actually using.
Kevin van Berkel
Kevin van Berkel 2013년 5월 3일
Hi Matt, thanks for your response.
s = size(A);
C = zeros(s);
for j1 = 1:s(1)
C(j1,:) = A(j1,:)*B((j1-1)*s(2)+1:j1*s(2),:);
end
and this yields me the the weight's vector 'C'. 'A' is also a 155x3 vector. So I only need to multiply every row with the transpose of the other vector. E.G. A(row 1,col 1-3)*C'(row 1, col 1-3)
Hope this clarifies my question. Thanks!

댓글을 달려면 로그인하십시오.

답변 (1개)

Kevin van Berkel
Kevin van Berkel 2013년 5월 3일
Hi Matt, thanks for your response.
s = size(A);
C = zeros(s);
for j1 = 1:s(1)
C(j1,:) = A(j1,:)*B((j1-1)*s(2)+1:j1*s(2),:);
end
and this yields me the the weight's vector 'C'. 'A' is also a 155x3 vector. So I only need to multiply every row with the transpose of the other vector. E.G. A(row 1,col 1-3)*C'(row 1, col 1-3)
Hope this clarifies my question. Thanks!

카테고리

Help CenterFile Exchange에서 Portfolio Optimization and Asset Allocation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by