original_docstring: Calculate Relative Strength Index(RSI) for given data.
  
      :param df: pandas.DataFrame
      :param period:
      :param field:
      :return: pandas.DataFrame
      
docstring: Calculate Relative Strength Index(RSI) for given data.
docstring_tokens: Calculate Relative Strength Index ( RSI ) for given data .
code: def relative_strength_index(df, period, field=None):
      """Calculate Relative Strength Index(RSI) for given data.
  
      :param df: pandas.DataFrame
      :param period:
      :param field:
      :return: pandas.DataFrame
      """
      field = field or 'Price'
      temp = copy.deepcopy(df)
      temp['Change'] = temp[field].diff()
      temp['Gain'] = temp['Change'].apply(lambda x: max([x, 0]))
      temp['Loss'] = temp['Change'].apply(lambda x: abs(min([x, 0])))
      temp['AG'] = temp['Gain'].rolling(window=period).mean()
      temp['AL'] = temp['Loss'].rolling(window=period).mean()
      return temp.apply(lambda x: 100 - 100 / (1 + x.AG / x.AL) if x.AL != 0 else 0, axis=1)
code_tokens: def relative_strength_index ( df , period , field = None ) : field = field or 'Price' temp = copy . deepcopy ( df ) temp [ 'Change' ] = temp [ field ] . diff ( ) temp [ 'Gain' ] = temp [ 'Change' ] . apply ( lambda x : max ( [ x , 0 ] ) ) temp [ 'Loss' ] = temp [ 'Change' ] . apply ( lambda x : abs ( min ( [ x , 0 ] ) ) ) temp [ 'AG' ] = temp [ 'Gain' ] . rolling ( window = period ) . mean ( ) temp [ 'AL' ] = temp [ 'Loss' ] . rolling ( window = period ) . mean ( ) return temp . apply ( lambda x : 100 - 100 / ( 1 + x . AG / x . AL ) if x . AL != 0 else 0 , axis = 1 )
short_docstring: Calculate Relative Strength Index(RSI) for given data.
short_docstring_tokens: Calculate Relative Strength Index ( RSI ) for given data .
comment: """Calculate Relative Strength Index(RSI) for given data.
  
      :param df: pandas.DataFrame
      :param period:
      :param field:
      :return: pandas.DataFrame
      """