TTR
TTR copied to clipboard
WMA calculation
Please see the example below. Is it a bug or something intentional?
> WMA(c(8, 8, rep(0, 10)), 3, c(6, 1, rep(0, 10)))
[1] NA NA 8 8 NaN NaN NaN NaN NaN NaN NaN NaN
> WMA(c(0.8, 0.8, rep(0, 10)), 3, c(0.6, 0.1, rep(0, 10)))
[1] NA NA 0.8 0.8 -2.0 -2.0 -2.0 -2.0 -2.0 -2.0 -2.0 -2.0
Session info -----------------------------------------------
setting value
version R version 3.2.2 (2015-08-14)
system x86_64, linux-gnu
ui RStudio (0.99.486)
language (EN)
collate en_US.UTF-8
tz <NA>
date 2015-10-13
Packages --------------------------------------------------
package * version date source
devtools 1.9.1 2015-09-11 CRAN (R 3.2.2)
digest 0.6.8 2014-12-31 CRAN (R 3.1.2)
lattice 0.20-33 2015-07-14 CRAN (R 3.2.1)
memoise 0.2.1 2014-04-22 CRAN (R 3.2.0)
rstudioapi 0.3.1 2015-04-07 CRAN (R 3.2.0)
TTR * 0.23-0 2015-07-10 CRAN (R 3.2.2)
xts 0.9-7 2014-01-02 CRAN (R 3.2.0)
zoo 1.7-12 2015-03-16 CRAN (R 3.1.3)
Not sure I'd call it a bug. It's a limitation of the current implementation of runSum
, which does not do any adjustments for rounding error due to floating-point arithmetic (i.e. Kahan summation).
This has already been implemented in some unexported C code in xts, and I'd prefer to use that instead of rewriting the functionality in TTR.