calc_varvec | R Documentation |
RcppArmadillo
.Calculate the variance of a single-column time series or a
vector using RcppArmadillo
.
calc_varvec(tseries)
tseries |
A single-column time series or a vector. |
The function calc_varvec()
calculates the variance of a
vector using RcppArmadillo
C++
code, so it's
significantly faster than the R
function var()
.
A numeric value equal to the variance of the vector.
## Not run:
# Create a vector of random returns
retp <- rnorm(1e6)
# Compare calc_varvec() with standard var()
all.equal(HighFreq::calc_varvec(retp), var(retp))
# Compare the speed of RcppArmadillo with R code
library(microbenchmark)
summary(microbenchmark(
Rcpp=HighFreq::calc_varvec(retp),
Rcode=var(retp),
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.