0

I would like to calculate rolling yearly differences based on a daily time series in R with a xts object. However, I see currently two issues:

  1. The number of trading days per year is not constant.
  2. There could be holes in the time series, e.g. one year could be missing in-between.

Are there functions available in the library to take such rolling differences without constant lags (e.g. a lag of 260 days could be off by 10 days sometimes)? Or would the correct approach here to search for each date the same date one year before (minus one or two days to account for weekends)?

p.vitzliputzli
  • 135
  • 1
  • 11
  • What output do you want when business days in one year fall on non-business days in the prior year (and vice versa)? – Joshua Ulrich Jun 04 '20 at 14:05
  • LOCF would be great, but I am worried that this could create problems in case a year of data is missing, i.e. 2015 would be missing, so the difference for 2016 to 2015 would be based on 2014 data. In that case, I would prefer to have NAs. – p.vitzliputzli Jun 04 '20 at 15:30
  • hi, can you provide sample data of those 2 issues and desired output? – chinsoon12 Jun 12 '20 at 01:34

0 Answers0