To calculate portfolio returns

조회 수: 3 (최근 30일)
Qian cao
Qian cao 2015년 11월 16일
답변: Guillaume 2015년 11월 16일
Hi, I have a question regarding the matrix multiplication with NaN cells in the matrix.
The two matrix are
W1= [0.1 0 0.9; 0 1/3 2/3; 1/3 1/3 1/3;0.2 0.4 0.4];
r=[0.2 0.1 NaN; -1 0 NaN; NaN 0.2 0.2; NaN 0.1 0];
The rows represent the time series. What I need is to get the vector R(t) which is the multiplication of W1(t-1)*r(t). That is R(2)=W1(1)*r(2)=[0.1 0 0.9]*[-1 0 NaN]=-0.1, R(3)=W1(2)*r(3)=[0 1/3 2/3]*[NaN 0.2 0.2]=0.2 and vice verse .I did it in the following way but the results do not show up as expected....Note: treat the NaN values as zeros:
for t=1:size(W1,1)
R(t,1)=W1(t-1,:)*returnm(t,:)';
end
Thank you very much for your help. I am waiting for that.

채택된 답변

Guillaume
Guillaume 2015년 11월 16일
If you want to treat the NaNs as zero, make them zero:
r(isnan(r)) = 0;
Your calculation is then simply
R = [NaN; sum(W1(1:end-1, :) .* r(2:end, :), 2)] %no loop needed
I've put NaN for R(1) since you haven't specified in your description what it should be. Personally, I would simply change the offsets of R (i.e. have R(1) = sum(W1(1) .* r(2)))

추가 답변 (0개)

카테고리

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