Moving Time Series to the Future with R

I am trying to move the time series (zoo facility) 7 days (trading week) forward into the future.

library(quantmod) getSymbols(c("AAPL"), from="2013-01-01", return.class="zoo") aapl <- Ad(AAPL) tail(aapl) 2013-05-07 2013-05-08 2013-05-09 2013-05-10 2013-05-13 2013-05-14 455.64 460.79 456.77 452.97 454.74 443.86 I want this: 2013-05-14 2013-05-15 2013-05-16 2013-05-17 2013-05-20 2013-05-21 455.64 460.79 456.77 452.97 454.74 443.86 

How is this possible? I tried a lot and could not ...

+4
source share
1 answer

Convert it to the zooreg class (so that it knows that it is regularly posted or almost like that), and then leave it appropriately:

 > lag(as.zooreg(tail(aapl)), -7) 2013-05-14 2013-05-15 2013-05-16 2013-05-17 2013-05-20 2013-05-21 455.64 460.79 456.77 452.97 454.74 443.86 

For more information, check out the ?zooreg examples section and read the comments, starting from where it reads:

 # lag and diff (as diff is defined in terms of lag) 
+2
source

Source: https://habr.com/ru/post/1480992/


All Articles