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
Alternatively, if you are using the package xts, then life is made incredibly simple. This is a straight copy-paste of a function I wrote myself a while ago:
ret<-function(x,k=1){ return(diff(log(x),k)) }