joshuaulrich / TTR

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

runSum produces leading NA when cumulative = TRUE #118

Closed ethanbsmith closed 2 years ago

ethanbsmith commented 2 years ago

Description

> TTR::runSum(1:10, n=1, cumulative = T)
 [1] NA  3  6 10 15 21 28 36 45 55

Expected behavior

expect runSum(x, n= 1, cumulative = T) to always match cumsum(x)

> cumsum(1:10)
 [1]  1  3  6 10 15 21 28 36 45 55

Minimal, reproducible example

`runSum(1:10, n= 1, cumulative = T)  == cumsum(1:10)`

FIx:

is.na(result) <- c(1:(n - 1 + NAs)) shoudl be: is.na(result) <- c(0:(n - 1 + NAs))

ethanbsmith commented 2 years ago

went to write a pr and see that this is fixed in dev with is.na(result) <- seq_len(n-1+NAs)

TY!

joshuaulrich commented 1 year ago

Note: this was fixed in 0fbb7bae9769e13f3f58f2f7ea363d448a8a97af