Re: [R] Linearize a Function

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Sun 29 Jan 2006 - 11:18:44 EST

  1. Have you looked at "cumsum"?
  2. What do you think you are computing when adding 100 to cumsum(log.returns)? To compute cumulative returns in percent from log.returns [or cumusum(log.returns)], compute exp(log.returns) or expm1(log.returns) = (exp(log.returns)-1). Similarly, to compute log.returns from simple.returns, compute log1p(simple.returns) = log(1+simple.returns) [making the obvious conversions between percentages and proportions]. Or am I missing something?
	  hope this helps,
	  spencer graves

Gottfried Gruber wrote:

> 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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Jan 29 11:25:59 2006

This archive was generated by hypermail 2.1.8 : Sun 29 Jan 2006 - 20:13:53 EST