[R-SIG-Finance] turning returns back into an index
Pierre Lapointe
pierrelap at gmail.com
Sun May 14 15:34:39 CEST 2017
cumprod(1+return_vector) to get an index starting from 1.
cumprod(1+return_vector)*100 to get an index starting at 100
On Sun, May 14, 2017 at 9:11 AM, blank <bruvnor at icloud.com> wrote:
> I’ve looked everywhere for a C optimised R library function that will
> accumulate returns with interim levels but can’t find it.
>
> so a function that is the inverse of Return.calculate() from
> PerformanceAnalytics
>
> or, something like this:
>
> rtns <- rnorm(100, sd=0.01)
> index <- vector(, length = length(rtns)+1)
> index[1] <- 100
> for ( i in 1:length(rtns) ) {
> index[i+1] <- index[i] * (1+rtns[i])
> }
>
> cheers.
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
[[alternative HTML version deleted]]
More information about the R-SIG-Finance
mailing list