I am curious how I revert from log-returns to prices. Here's an example:
> a1 <- c(88.23, 88.44, 88.55, 88.77, 88.99)
> a1
[1] 88.23 88.44 88.55 88.77 88.99
> a2 <- diff(log(a1))
> a2
[1] 0.002377315 0.001243008 0.002481391 0.002475249
a1 is prices, a2 is returns. How would I go from a2 back to 开发者_开发知识库a1? Any suggestions would be great.
You want to use something like
a3 <- exp(cumsum(a2))
Alternatively, you could use
a3 <- cumprod(exp(a2))
But these will be off because you need to add back the initial price to each value.
That should do:
> Reduce(function(x,y) {x * exp(y)}, a2, init=a1[1], accumulate=T)
[1] 88.23 88.44 88.55 88.77 88.99
精彩评论