フィルターのクリア

To calculate portfolio returns

2 ビュー (過去 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 Center および File ExchangePortfolio 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