Calculate RSI indicator from pandas DataFrame?

前端 未结 3 1755
甜味超标
甜味超标 2021-01-02 06:36

My problem

I tried many libraries on Github but all of them did not produce matching results for TradingView so I followed the fo

3条回答
  •  清酒与你
    2021-01-02 07:00

    There is an easier way, the package talib.

    import talib   
    close = df['close']
    rsi = talib.RSI(close, timeperiod=14)
    

    If you'd like Bollinger Bands to go with your RSI that is easy too.

    upperBB, middleBB, lowerBB = talib.BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)
    

    You can use Bollinger Bands on RSI instead of the fixed reference levels of 70 and 30.

    upperBBrsi, MiddleBBrsi, lowerBBrsi = talib.BBANDS(rsi, timeperiod=50, nbdevup=2, nbdevdn=2, matype=0)
    

    Finally, you can normalize RSI using the %b calcification.

    normrsi = (rsi - lowerBBrsi) / (upperBBrsi - lowerBBrsi)
    

    info on talib https://mrjbq7.github.io/ta-lib/

    info on Bollinger Bands https://www.BollingerBands.com

提交回复
热议问题