how to calculate portfolio return series in matlab? -


i have asset return matrix(t*n) , asset weight vector(1*n) t number of obs n asset.if asset return matrix r(i) , asset weight vector b w(i), want sum(r(i)*w(i)), i=1:n t*1 matrix.how can calculate in matlab?

example:

x =  0.1400    0.2100    0.1800 0.1100    0.1200    0.1500 0.1700    0.1600    0.1700 0.1800    0.2100    0.1400  w =  0.3000    0.2000    0.5000     

then want matrix:

r(1,1)=(0.14*0.3)+(0.21*0.2)+(0.18*0.5)=?  r(2,1)=(0.11*0.3)+(0.12*0.2)+(0.15*0.5)=?  r(3,1)=...  r(4,1)=... 

thanks

you can multiply x w transposed. note .' transpose, not '. so, want simply:

x * w.'     ans =      0.1740     0.1320     0.1680     0.1660 

otherwise, if want practice bsxfun:

use bsxfun take product of x , w each column, , sum(.., 2) sum along second dimension, this:

sum(bsxfun(@times, x, w),2) ans =      0.1740     0.1320     0.1680     0.1660 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -