Back to Community
Why many stocks have 0 RSI value?

Hi,

I'm using ta.RSI to run through about 79 stocks and many of stocks have 0 for RSI(2) value. The code is really simple. Can anyone help?

-Terry

Clone Algorithm
4
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 53a03b273bf39f072fd13ac7
There was a runtime error.
10 responses

A comparison between ta.RSI() and talib.RSI()

[Edit: Bug 40 should have been -40 so updated backtest below b/c not able to change a backtest in-place on editing a msg.
The change clears up some gaps in record() output.]

Clone Algorithm
7
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 53a0689743a01c0704d512da
There was a runtime error.

ta and talib should produce the same results. If possible can you share the URL of the other TA library?

Which of the above has the correct implementation?

I tested talib and it works. Gary Thanks

Terry

Clearing bug where 40 should have been -40.
(Probably could have been -4 since rsi_window was small, anyway, for visitors from the future, obviously suit to your purposes and spot-check values against charting sites)

Clone Algorithm
7
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 53a1dd7cf0979e071b401688
There was a runtime error.

I just did some testing of a few different indicators and the ta version is usually the one that came up different. I wrote a custom version of the Williams %R indicator to test the other 2 against. In minute mode I had to multiply the window by 390 (minutes/day) in the ta version to produce the same results for all 3 calculations. I trust the talib versions, they seem to work correctly, and you can be explicit about the data that gets passed to it. There's also no warmup period in minute mode if you use talib.

Clone Algorithm
1
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 53a1e71dd87caf073e5c7a81
There was a runtime error.

This may help clarify some of the confusion around the technical indicators. In the Quantopian IDE there is a difference (though not intentionally) between 'import talib' and using the 'ta.' notation.

When you do "import talib", you are referencing the open-sourced python library in your algorithm. This is the recommended approach and will return the correct values in your code.

When we first started, we created a Quantopian-specific wrapper, called "ta." to help use the talib library on Quantopian functions. However, as we've grown and built new functions, it's shown some holes and we're not working to support it. In fact, we're working to deprecate this.

For your strategy, use talib.RSI - this will return the values you're expecting.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

I think Quantopain can provide test data and its corresponding ta result. When user hit build button, it can at least run through the test set to make sure its own library is working properly.

Terry

@Alisa, if ta is no longer in use or deprecated, perhaps the RSI example on the Help page should be edited?
https://www.quantopian.com/help#RSI
It still makes reference to ta.RSI
Thanks

The docs have been updated! See: https://www.quantopian.com/help#api-talib