I\'m trying to get a time series of returns for holding a certain asset for a specific time.
My dataframe looks like this:
Date Price
1998-01-01
Sample Data
price <- matrix(c(20,22,21,25,25,19,20,30,28,25,26,27,30,32,31,30),ncol= 1);
Calculate 1 day Log Return
OneDayLogReturn <- c(diff(log(price)));
Calculate 10 days Log Return
TenDaysLogReturn <- c(diff(log(price),10))
results:
0.2623643 0.2047944 0.3566749 0.2468601 0.2151114 0.4567584
verify by :
for (i in 1:6) {print(log(price[10+i]/price[i]))}
Similarly, 20 Days return can be calculated using larger sample date and use
c(diff(log(price),20))
or in your case
c(diff(log(price$Return),20))