rolling_beta() is a generic S3 function that preserves
the input class: double vector in, double vector out.
Handling of NA values
Leading NAs are always produced for the initial lookback period
where insufficient data is available. If the input itself contains
NAs, the behaviour depends on na.bridge:
na.bridge = FALSE(default)NAs propagate through the TA-Lib C routine. Because rolling statistics smooth across time, a singleNAin the input typically poisons every subsequent value.na.bridge = TRUEInput
NAs are stripped, the statistic is computed on the dense series, andNAs are re-inserted at the original positions. Output length matches input length, but the computation treats non-consecutive observations as if they were adjacent - fine for sparse missing values, misleading across clustered gaps.
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.bridge
(logical). A logical of length 1. FALSE by default. When FALSE, input
NAs propagate through the TA-Lib C routine (the rolling computation typically fills the remaining output withNA). When TRUE, inputNArows are stripped before computation and re-inserted at the original positions in the output, causing the statistic to treat non-consecutive non-NAobservations as if they were adjacent - see the Handling ofNAvalues section above for the consequences.
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.059393218 0.148890916 0.097389648 0.099125915 -0.375657597
#> [6] 0.009603153
