I have the following dataframe:
dat <- tibble::tribble( ~date , ~pct_monthly_return,
2021-01-31, 0.0023,
2021-02-28, 0.01,
2021-03-31, 0.035)
I would like to create a new column called index which starts at 100 a month before the dataframe starts (i.e. 2020-12-31 in my example). The index of 100 must then be compounded by pct_monthly_return variable so that I can see how the index grows over time.
The result should produce the following dataframe:
date pct_monthly_return index
2020-12-31 0 100
2021-01-31 0.0023 100.23
2021-02-28 0.01 101.2323
2021-03-31 0.035 104.7754