I am trying to annualize negative returns, and running into an issue. I have an xts series, and I am using the following code:
x = rebalReturns[,"LBND/SBND (PS DB 25+ Year T-Bond)"]
round((tail(cumprod(na.omit(x) + 1) - 1,1)), 4)^round(1/length(na.omit(x)),4)
This returns 'NaN'.
If I calculate the two halves separately, I get:
> round((tail(cumprod(na.omit(x) + 1) - 1,1)), 4)
LBND/SBND (PS DB 25+ Year T-Bond)
2015-04-02 -0.2274
> round(252/length(na.omit(x)),4)
[1] .2184
>
And if I calculate this manually, I get a meaningful result:
> -.2274^.2184
[1] -0.7236408
>
I get there are some peccadilloes around exponentiation with negative numbers, but why is it working manually, and not with the xts object?? Is there a way to do this?
Thanks!!
I am not bright. This is NOT how you annualize returns. (And I misunderstood the order of operations. (Thanks, Dason.))
The formula should be:
round(1 + (tail(cumprod(na.omit(x) + 1) - 1,1)), 4)^round(252/length(na.omit(x)),4) - 1
And this works just fine. I apologize for wasting anyone's efforts, and as always thanks for your help!