It's possible for a user to specify a center argument that has more NA than the number of NA in x + n - 1. This can even happen internally, for example with CCI:
R> require(TTR)
R> data(ttrc)
R> cci <- CCI(ttrc$Close, maType="DEMA")
Error in runMAD(HLC, n, center = mavg, stat = "mean") :
NA/NaN/Inf in foreign function call (arg 2)
This is because DEMA has more NA than n, due to double-smoothing.
R> dema <- DEMA(ttrc$Close, n=10)
R> runMAD(ttrc$Close, n=10, center=dema)
Error in runMAD(ttrc$Close, n = 10, center = dema) :
NA/NaN/Inf in foreign function call (arg 2)
R> sum(is.na(dema))
[1] 18
One possible solution is to set NAs to max(sum(is.na(x)), sum(is.na(center))) when center is user-specified. Note that we should also check for non-leading NA in center, as we do forx`.
It's possible for a user to specify a
center
argument that has moreNA
than the number ofNA
inx
+n - 1
. This can even happen internally, for example withCCI
:This is because
DEMA
has moreNA
thann
, due to double-smoothing.One possible solution is to set
NAs
tomax(sum(is.na(x)), sum(is.na(center)))
whencenter
is user-specified. Note that we should also check for non-leadingNA
incenter, as we do for
x`.