calc_varvec: Calculate the variance of a single-column _time series_ or a...

View source: R/RcppExports.R

calc_varvecR Documentation

Calculate the variance of a single-column time series or a vector using RcppArmadillo.

Description

Calculate the variance of a single-column time series or a vector using RcppArmadillo.

Usage

calc_varvec(tseries)

Arguments

tseries

A single-column time series or a vector.

Details

The function calc_varvec() calculates the variance of a vector using RcppArmadillo C++ code, so it's significantly faster than the R function var().

Value

A numeric value equal to the variance of the vector.

Examples

## 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)


algoquant/HighFreq documentation built on Feb. 9, 2024, 8:15 p.m.