def compute_rsi(data, time_window):
    """
    Compute rsi values
    :param data: dataframe for calculate rsi
    :param time_window: time window, ex: 14 (for 14 data times)
    :return:
    """
    diff = data.diff(1).dropna()  # drop na (if any)

    # Get only the dimension of the differences
    up_chg = 0 * diff
    down_chg = 0 * diff

    # Get changes
    up_chg[diff > 0] = diff[diff > 0]
    down_chg[diff < 0] = diff[diff < 0]

    # Calculate averages
    up_chg_avg = up_chg.ewm(com=time_window-1, min_periods=time_window).mean()
    down_chg_avg = down_chg.ewm(com=time_window-1, min_periods=time_window).mean()

    rs = abs(up_chg_avg / down_chg_avg)
    rsi = 100 - 100 / (1 + rs)

    return rsi