joshuaulrich / TTR

Technical analysis and other functions to construct technical trading rules with R
GNU General Public License v2.0
330 stars 103 forks source link

runMean(..., cumulative = TRUE) doesn't account for leading NA in denominator #122

Closed joshuaulrich closed 1 year ago

joshuaulrich commented 2 years ago
x <- c(rep(NA_real_, 5), 1:5) 
TTR::runMean(x, 1, cumulative = TRUE)
## [1]     NA     NA     NA     NA     NA     NA 0.4285714 0.7500000 1.1111111 1.5000000

# but the non-NA values should be
cumsum(1:5) / 1:5
## [1] 1.0 1.5 2.0 2.5 3.0