Rstudent
Rstudent

Reputation: 41

RSI output varies even with set n of days in TTR

I want to get RSI for some ETFs so I run the following codes

startDate<- '2015-09-01'
endDate<-'2015-11-01'
etfs<-c("XLE")
tickers <- get(getSymbols(etfs, from=startDate, to=endDate, auto.assign=TRUE))
RSIdataset <- RSI(Ad(tickers),n=14)
tail(RSIdataset)

and I got the following output:

                EMA
2015-10-23 58.91729
2015-10-26 51.03857
2015-10-27 47.74480
2015-10-28 53.62664
2015-10-29 54.89976
2015-10-30 56.63444

But when I change the start day to 2015-07-01,and keep other codes the same, I got:

                EMA
2015-10-23 57.69569
2015-10-26 50.29627
2015-10-27 47.17508
2015-10-28 52.91749
2015-10-29 54.16700
2015-10-30 55.87331

My question is why the RSI outputs are different when startDate changes even when n=14 is set, and for the same date (for example 2015-10-30). Shouldn't only the 14 days before 2015-10-30 matter? which in this case should be the same regardless what startDate is? thank you in advance

Upvotes: 1

Views: 147

Answers (1)

Joshua Ulrich
Joshua Ulrich

Reputation: 176688

The result will always be different if you change the start date and you use the default moving average (or any recursive moving average). See the Warning section in ?MovingAverages:

Some indicators (e.g. EMA, DEMA, EVWMA, etc.) are calculated using the indicators' own previous values, and are therefore unstable in the short-term. As the indicator receives more data, its output becomes more stable. See example below.

The relevant example is:

## Example of short-term instability of EMA
## (and other indicators mentioned above)
x <- rnorm(100)
tail( EMA(x[90:100],10), 1 )
tail( EMA(x[70:100],10), 1 )
tail( EMA(x[50:100],10), 1 )
tail( EMA(x[30:100],10), 1 )
tail( EMA(x[10:100],10), 1 )
tail( EMA(x[ 1:100],10), 1 )

Upvotes: 2

Related Questions