Open DataStrategist opened 3 years ago
Found it. It freaks out if High == Low == Close. Is that expected behavior?
Yes, that is expected behavior. There is no volatility, so the math doesn't work. You get div by zero.
Fair enough. May I make a gentle recommendation as a package builder to "capture that error" perhaps using try
or purrr::safely
and then output a more human readable error using stop
? But otherwise, it's cool... anyway these strategies don't really work on the 1 min candlesticks (which is where you can get the exactly the same values). :)
You may close if you wish.
These technical indicators were developed on daily bars.
I think NA is the appropriate result. how you choose to handle those NA's is up to you. It seems that there are multiple different arguably reasonable responses to an indicator returning an NA. You as an analyst need to decide what the proper handling is for the analysis or strategy that you are trying to create.
Thanks for the report, closing.
There is no volatility, so the math doesn't work. You get div by zero.
While that's true, stoch()
tries to account for it. It sets fastK
to 0.5 if it's not NA
or not finite. I did that to fix #52, but it only works for Inf
, not NaN
. This is a bug that should be fixed.
At minimum, I agree with @DataStrategist that the error should be more informative.
Yeah, I was gonna let it rest because it doesn't really matter, but the reason Error in runSum(x, n): Series contains non-leading NAs
is technically incorrect is that in my original reprex there are no NA
s.
Anyway, thanks for a great package, and good luck trading!
The error is because the fastK
calculations creates NAs, not that they're in your original series. That's why the error needs to be more informative... or the case should be handled automatically by setting Inf and NaN to 0.5.
I may add a warning to let the user know that their series isn't well-suited to using stoch()
because of its invariant characteristics. If I do, I would also add a warning = TRUE
arg you could set to FALSE
to suppress it.
Hello, I think the same error appears also with the EMV() function. So everything said above may apply to that function too. Let me add my observation, that the equality in high, low, close, close_adj appears on days, when the asset simply was not traded at all.
Description
I'm trying to run the
stoch
function on some data but I'm getting the above referenced error.Expected behavior
I'm expecting the function to return expected output of 3 columns
Minimal, reproducible example
Session Info