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
You can just use offset indices by subtracting from a range. (.... but remember that R does not use 0 as a valid index.) Let's say your prices are the second column in a dataframe named prcs2 the first three returns with an interval of 19 days with your data would be :
prcs2[ (20:22)-19, 2] <-c(20,22,21)
prcs2[ (20:22), 2] <-c(25,19,20)
log(prcs2[20:22, 2]/prcs2[ (20:22)-19, 2])
#[1] 0.22314355 -0.14660347 -0.04879016