| roll_scale | R Documentation |
RcppArmadillo.Perform a rolling standardization (centering and scaling) of the columns of
a time series of data using RcppArmadillo.
roll_scale(matrix, lookb, center = TRUE, scalit = TRUE, use_median = FALSE)
timeser |
A time series or matrix of data. |
lookb |
The length of the look-back interval, equal to the number of rows of data used in the scaling. |
center |
A Boolean argument: if |
scalit |
A Boolean argument: if |
use_median |
A Boolean argument: if |
The function roll_scale() performs a rolling standardization
(centering and scaling) of the columns of the timeser argument
using RcppArmadillo.
The function roll_scale() performs a loop over the rows of
timeser, subsets a number of previous (past) rows equal to
lookb, and standardizes the subset matrix by calling the
function calc_scale(). It assigns the last row of the standardized
subset matrix to the return matrix.
If the arguments center and scalit are both TRUE and
use_median is FALSE (the defaults), then
calc_scale() performs the same calculation as the function
roll::roll_scale().
If the arguments center and scalit are both TRUE (the
defaults), then calc_scale() standardizes the data.
If the argument center is FALSE then calc_scale()
only scales the data (divides it by the standard deviations).
If the argument scalit is FALSE then calc_scale()
only demeans the data (subtracts the means).
If the argument use_median is TRUE, then it calculates the
centrality as the median and the dispersion as the median
absolute deviation (MAD).
A matrix with the same dimensions as the input argument
timeser.
## Not run:
# Calculate a time series of returns
retp <- zoo::coredata(na.omit(rutils::etfenv$returns[, c("IEF", "VTI")]))
lookb <- 11
rolled_scaled <- roll::roll_scale(retp, width=lookb, min_obs=1)
rolled_scaled2 <- HighFreq::roll_scale(retp, lookb=lookb)
all.equal(rolled_scaled[-(1:2), ], rolled_scaled2[-(1:2), ],
check.attributes=FALSE)
## End(Not run) # end dontrun
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.