1

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?

Datageek
  • 521
  • 2
  • 8
  • 12
  • 3
    I need to investigate more, but it looks like this may be a bug in TTR::RSI. – Joshua Ulrich Jan 21 '15 at 01:11
  • 1
    Reading the source of TTR, it appears an EMA is being used by default on the diffs in price, Datageek: Are you specifying SMA? – Kyle Balkissoon Jan 21 '15 at 06:06
  • I am specifying SMA indeed. SMA however is simply "sum of gains over last x days". It doesn't use the "previous average gain x (x-1) + last gain / x" logic. – Datageek Jan 21 '15 at 11:44
  • 2
    SMA is 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
  • Agree, SMA is a moving average over x days, i.e. mean. I am simply stating this RSI is not the same as what Bloomberg computes and was wondering how to calculate exactly the same results in TTR. – Datageek Jan 21 '15 at 12:59
  • The default should be close, except for the issue I mentioned in my previous comment. – Joshua Ulrich Jan 21 '15 at 15:39
  • @JoshuaUlrich it is not very close actually. See my edit. – Datageek Jan 21 '15 at 16:31
  • Of course that's not close! If you use a different moving average, why would you expect the results to be the same? I said the default should be close. – Joshua Ulrich Jan 21 '15 at 16:44
  • @JoshuaUlrich You are right! I was trying EMA, SMA, etc but they did differ. Using default parameters produces indeed the closest value. – Datageek Jan 21 '15 at 16:51
  • @Datageek : How are you getting a different answer with EMA and the default? – Kyle Balkissoon Jan 21 '15 at 21:21
  • @KyleBalkissoon The default seems to be using also maArgs$wilder parameter:

    if (missing(maType)) { maType <- "EMA" maArgs$wilder <- TRUE }

    – Datageek Jan 22 '15 at 10:55
  • Has anyone found an answer to this? I have been looking at stockcharts and tradingview. It is nowhere close to RSI in TTR – geodex Jan 05 '17 at 21:14

0 Answers0