(df, r, s)
return out(SETTINGS, df, result)
True Strength Index
True Strength Index
True Strength Index
def TSI(df, r, s):
    """
    True Strength Index
    """
    M = pd.Series(df['Close'].diff(1))
    aM = abs(M)
    EMA1 = pd.Series(M.ewm(span=r, min_periods=r - 1).mean())
    aEMA1 = pd.Series(aM.ewm(span=r, min_periods=r - 1).mean())
    EMA2 = pd.Series(EMA1.ewm(span=s, min_periods=s - 1).mean())
    aEMA2 = pd.Series(aEMA1.ewm(span=s, min_periods=s - 1).mean())
    result = pd.Series(EMA2 / aEMA2, name='TSI_' + str(r) + '_' + str(s))
    return out(SETTINGS, df, result)
def TSI ( df , r , s ) : M = pd . Series ( df [ 'Close' ] . diff ( 1 ) ) aM = abs ( M ) EMA1 = pd . Series ( M . ewm ( span = r , min_periods = r - 1 ) . mean ( ) ) aEMA1 = pd . Series ( aM . ewm ( span = r , min_periods = r - 1 ) . mean ( ) ) EMA2 = pd . Series ( EMA1 . ewm ( span = s , min_periods = s - 1 ) . mean ( ) ) aEMA2 = pd . Series ( aEMA1 . ewm ( span = s , min_periods = s - 1 ) . mean ( ) ) result = pd . Series ( EMA2 / aEMA2 , name = 'TSI_' + str ( r ) + '_' + str ( s ) ) return out ( SETTINGS , df , result )