Closed stellathecat closed 3 years ago
Thanks for the report. This looks like a bug, and my hypothesis is that it's an artifact of the missing values at the beginning of your series.
For example, here's the plot of the two running median calculations, with the NA in the series.
weird <-
cbind(test,
ttr = TTR::runMedian(test, n = 20, cumulative = TRUE),
perf = PerformanceAnalytics::apply.fromstart(test, median, na.rm = TRUE))
x <- xts(weird, index(test))
plot(x)
And here's the same plot with the leading NA removed.
test2 <- na.omit(test)
weird2 <-
cbind(test2,
ttr = TTR::runMedian(test2, n = 20, cumulative = TRUE),
perf = PerformanceAnalytics::apply.fromstart(test2, median, na.rm = TRUE))
x2 <- xts(weird2, index(test2))
plot(x2)
I need to do some more digging to make sure this is the root cause, then I'll work on a fix. Thanks again for the report!
This is fixed in master now. I also fixed the same issue in runMAD()
. Thanks again for the report!
Description
runMedian(..., cumulative = T) produces strange results which I am unable to trace.
Expected behavior
[Describe the behavior/output you expected]
The three columns should be identical (after obs 20) - which they are in this example.
Minimal, reproducible example
Same results when I use as.numeric(...) as input.
Input series is declining, but runMedian is suddenly jumping up?
Session Info