The implementation of TTR:RSI differs slightly from the RSI calculated in Bloomberg, see more details here.
I use in TTR the SMA, which simply calculates the mean, that is a walking window of:
Sum of gains and losses over the 14 days (assuming it's the 14 days period)
In Bloomberg this is done only for first 14 days, subsequent days are calculated as:
[(previous average gain) x 13 + last gain] / 14
I suspect it should be enough to swap SMA with a custom moving average function. Was just wondering if such a function is already a part of TTR or is easy to implement?
TTR::RSI. – Joshua Ulrich Jan 21 '15 at 01:11SMAis not the "sum of gains over last x days"; it's the mean. I don't understand why you're confused that the results are different when you specify a different moving average. I would be concerned if they were the same. The potential bug I referred to is that the positive/negative values are set to zero (instead of missing) when calculating the down/up averages, respectively. – Joshua Ulrich Jan 21 '15 at 12:39
– Datageek Jan 22 '15 at 10:55if (missing(maType)) { maType <- "EMA" maArgs$wilder <- TRUE }