Calculating future returns in R

I have a dataset that has ohlc prices, I want to know how to calculate the log returns of the next 20 day period for all dates in the dataset. Each date in the dataset is the starting and the next 20 days is the final point.

log(close, lag(close, n=20))

The code above was suggested by GPT but I think it's wrong because it uses lag().

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.