Skip to content
Prev 13573 / 15274 Next

Calculating trailing returns

On Mon, Oct 26, 2015 at 9:53 AM, Am Gut <agquantr at gmail.com> wrote:

            
You're not passing the function argument correctly (you're passing
'trim=function(x) prod(1+x)-1'). Check the function signature.

library(PerformanceAnalytics)
data(managers)
M1 <- managers[, 1, drop=FALSE]

apply.rolling(M1, width=5, FUN=function(x) prod(1+x)-1)[5] ## cumulative
return of first 5 observations

## compare to manual calculation
prod(M1[1:5]+1) - 1


Michael