Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runMAD should check for NA if user specifies center argument #25

Open
joshuaulrich opened this issue Mar 22, 2016 · 0 comments
Open

runMAD should check for NA if user specifies center argument #25

joshuaulrich opened this issue Mar 22, 2016 · 0 comments
Assignees
Labels

Comments

@joshuaulrich
Copy link
Owner

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`.

@joshuaulrich joshuaulrich self-assigned this Mar 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant