[R] Linearize a Function
Gottfried Gruber
ggruber at terminal.at
Tue Jan 24 23:11:13 CET 2006
hi,
i calculate the log-returns in return1 and i want to get the performance for
the security. with only one security i have the following code
# create matrix to keep performance
return100=matrix(rep(100,length(return1)+1))
# matrix for the sum
z1=matrix(rep(0,length(return1)+1))
# suming up the returns from current index to start
for (i in 1:length(return1)) {z1[i+1]=sum(return1[c(1:i)]) }
#adding both matrices
return100=return100+z1*100
this works fine for a 1 x n matrix, but if i want the same for a n x m matrix
i assume the above code will get time-consuming. is there a trick to
linearize the for-loop or any other solution?
thanks for any solution & effort,
tia gg
--
---------------------------------------------------
Gottfried Gruber
mailto:gottfried.gruber at terminal.at
www: http://gogo.sehrsupa.net
More information about the R-help
mailing list