roll_varvec | R Documentation |
RcppArmadillo
.Calculate a vector of variance estimates over a rolling look-back
interval for a single-column time series or a single-column
matrix, using RcppArmadillo
.
roll_varvec(tseries, lookb = 1L)
tseries |
A single-column time series or a single-column matrix. |
lookb |
The length of the look-back interval, equal to the
number of vector elements used for calculating a single variance
estimate (the default is |
The function roll_varvec()
calculates a vector of variance
estimates over a rolling look-back interval for a single-column time
series or a single-column matrix, using RcppArmadillo
C++
code.
The function roll_varvec()
uses an expanding look-back interval in
the initial warmup period, to calculate the same number of elements as the
input argument tseries
.
The function roll_varvec()
performs the same calculation as the
function roll_var()
from package
RcppRoll,
but it's several times faster because it uses RcppArmadillo
C++
code.
A single-column matrix with the same number of elements as
the input argument tseries
.
## Not run:
# Create a vector of random returns
retp <- rnorm(1e6)
# Compare the variance estimates over 11-period look-back intervals
all.equal(drop(HighFreq::roll_varvec(retp, lookb=11))[-(1:10)],
RcppRoll::roll_var(retp, n=11))
# Compare the speed of RcppArmadillo with RcppRoll
library(microbenchmark)
summary(microbenchmark(
Rcpp=HighFreq::roll_varvec(retp, lookb=11),
RcppRoll=RcppRoll::roll_var(retp, n=11),
times=10))[, c(1, 4, 5)] # end microbenchmark summary
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.