Reputation: 5807
MyVector<-c(0.5, 0.3, -0.2)
Result1<-Return.cumulative(MyVector)
Result2<-exp(cumsum(MyVector))
I want to basically plot Result2
and show in a summary the value of Result1
. But as far as I thought, the last entry of Result2 * MyVector[1]
should be the same as the value of Result1
isn't it? Because it is a cumulative return...or at least that's what I want. Where is my mistake?
I want to basically plot a investment return and show the total return in a table. And I always index the investment vehicle to 1 so I thought the last data point of the plot should be the exact same value as the total return in the table...
EDIT:
Return.cumulative:
function (R, geometric = TRUE)
{
if (is.vector(R)) {
R = na.omit(R)
if (!geometric)
return(sum(R))
else {
return(prod(1 + R) - 1)
}
}
else {
R = checkData(R, method = "matrix")
result = apply(R, 2, Return.cumulative, geometric = geometric)
dim(result) = c(1, NCOL(R))
colnames(result) = colnames(R)
rownames(result) = "Cumulative Return"
return(result)
}
}
Upvotes: 0
Views: 8140
Reputation: 269526
This:
prod(1+MyVector) - 1
## [1] 0.56
gives the same answer as:
library(PerformanceAnalytics)
Return.cumulative(MyVector)
## [1] 0.56
Please make all code posted to SO reproducible and self-contained. That includes all necessary library
stateemnts. It is not necesasry to copy and post the source code from packages you are using.
Upvotes: 5