rolling_beta() is a generic S3 function that preserves
the input class: double vector in, double vector out.
Handling of -values
Leading NAs are always produced for the initial lookback period
where insufficient data is available. If the input itself contains
NAs they are passed through to the underlying C routine, which
can cause the entire output to be filled with NAs. Set
na.ignore = TRUE to strip NAs before calculation and
re-insert them at their original positions in the output.
Arguments
- x, y
((double), (double)). A pair of double vectors of equal length.
- n
(integer). Lookback period (window size). A positive integer of length 1.
- na.ignore
(logical). A logical of length 1. FALSE by default. If TRUE,
NAs in the input are stripped before calculation and re-inserted at their original positions in the output.
See also
Other Rolling Statistic:
rolling_correlation(),
rolling_max(),
rolling_min(),
rolling_standard_deviation(),
rolling_sum(),
rolling_variance()
Examples
## load Bitcoin (BTC)
## series
data(BTC, package = "talib")
## calculate the rolling statistic
## between Open and Close
output <- talib::rolling_beta(x = BTC[[1]], y = BTC[[4]])
## display the results
utils::tail(output)
#> [1] 0.167234235 0.141477872 0.212146797 0.004301746 0.069313219 0.054557930
