To calculate portfolio returns
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
Find more on Portfolio Optimization and Asset Allocation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!