Relative Strength Index in python pandas

前端 未结 12 1455
生来不讨喜
生来不讨喜 2020-12-07 17:29

I am new to pandas. What is the best way to calculate the relative strength part in the RSI indicator in pandas? So far I got the following:

from pylab impor         


        
12条回答
  •  借酒劲吻你
    2020-12-07 18:01

    def RSI(series):
        delta = series.diff()
        u = delta * 0 
        d = u.copy()
        i_pos = delta > 0
        i_neg = delta < 0
        u[i_pos] = delta[i_pos]
        d[i_neg] = delta[i_neg]
        rs = moments.ewma(u, span=27) / moments.ewma(d, span=27)
        return 100 - 100 / (1 + rs)
    

提交回复
热议问题