roll_varvec: Calculate a _vector_ of variance estimates over a rolling...

View source: R/RcppExports.R

roll_varvecR Documentation

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.

Description

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.

Usage

roll_varvec(tseries, lookb = 1L)

Arguments

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 lookb = 1).

Details

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.

Value

A single-column matrix with the same number of elements as the input argument tseries.

Examples

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

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