lagxts | R Documentation |
Apply a time lag to an xts time series.
lagxts(xtsv, lagg = 1, pad_zeros = TRUE, ...)
xtsv |
An xts time series. |
lagg |
An integer equal to the number of time periods of lag
(default is |
pad_zeros |
A Boolean argument: Should the output be
padded with zeros? (The default is |
... |
Additional arguments to function |
Applies a time lag to an xts time series and pads with the
first and last elements instead of NA
s.
A positive lag argument lagg
means elements from lagg
periods
in the past are moved to the present. A negative lag argument lagg
moves elements from the future to the present.
If lagg = 0
, then lagxts()
returns the input time series
unchanged.
To avoid leading or trailing NA
values, the output xts is padded
with zeroes, or with elements from either the first or the last row.
For the lag of asset returns, they should be padded with zeros, to avoid look-ahead bias. For the lag of prices, they should be padded with the first or last prices, not with zeros.
The function lagxts()
is just a wrapper for function
lag.xts()
from package
xts, but it
pads with the first and last elements instead of NA
s.
The function lagit()
has incorporated the functionality of
lagxts()
, so that lagxts()
will be retired in future
package versions.
An xts time series with the same dimensions and the same time
index as the input xtsv
time series.
# Lag by 10 periods
rutils::lagxts(rutils::etfenv$VTI, lag=10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.