Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
RSI calculation

I use the below codes to calculate the RSI value of MSFT. The backtest results show MSFT's RSI is 73.51 at the last date point (02/28/2014). But I checked several finance website and none of them says MSFT's RSI is over 70 at that day. What is problem of my codes?

4 responses

Hello IWF,

This has been asked a few times and it relates to the implementation of TA-Lib in Quantopian. As Quantopian is a backtesting platform it is desirable to calculate the same value for an indicator like RSI irrespective of the algo start date, especially when 'walk-forward' testing.

The author(s) of TA-Lib discuss this "crazy" idea here http://ta-lib.org/d_api/ta_setunstableperiod.html and there are threads discusing it here https://www.quantopian.com/posts/signals-values-different-from-other-tools-how-can-you-trust-them and here https://www.quantopian.com/posts/ta-dot-macd-values-dont-match-google-or-yahoo-finance-charts

P.

The Relative Strength Index (RSI) compares current state to recent gains and losses and
    is significant:

"extremely popular momentum indicator" stockcharts.com
"extremely versatile indicator" finance.yahoo.com
"true" forex-markets.com
"One of the more universally accepted" dailyfx.com
"most powerful" stockfetcher.com

It can be calculated in numerous ways (SMA, EMA, WMA, DEMA, Wilder, Cutler).

I don't know what method popular charting sites use (Google, TradingView, Yahoo, Stockcharts, BarChart, YCharts etc), just that I think they are
    similar to each other.
Quantopian stands alone in its RSI values currently (May 2014) [correct me if I'm wrong please].

Quantopian can nudge forward toward the central envy of the industry by offering users
    -- an option for the rudimentary method that those other sites use, whatever it might be, (add this)
    -- plus an option for the more "desirable" method. (current, keep)

I want RSI values to match those charting sites as an essential starting point, the oxygen of visual confirmation, cross-ref. Then play.

So ok, below are a couple of ways to obtain RSI values on Quantopian pretty close to charting sites, TradingView, Google, et al...

Yeah, actually, about the previous post, I agree with myself that maybe it could be awesome to have options at some point in the future for the various ways of calculating RSI,
though I realize now that fairly closely matching values here are obtainable, hurray.
It's basically a matter of using talib.RSI() [not ta.RSI] and feeding it the history of prices.
[Ideally we would just give it a lookback window size alone and it would figure out a way to round up prices, however this is not an ideal planet (yet, it's only 2014)]

For RSI calculation, this website explained in details. https://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:relative_strength_index_rsi Taking the prior value plus the current value is a smoothing technique similar to that used in calculating an exponential moving average. This also means that RSI values become more accurate as the calculation period extends. The smoothing process affects RSI values. RSI values are smoothed after the first calculation. Because of this smoothing, RSI values may differ based on the total calculation period.