首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何计算连接RSI (CRSI)

如何计算连接RSI (CRSI)
EN

Stack Overflow用户
提问于 2022-02-17 11:01:14
回答 1查看 483关注 0票数 0

我在计算康纳的RSI (CRSI)。RSI和ROC给出了正确的结果,但由于条纹,我得到的CRSI不正确的结果。有人知道如何正确计算吗?

代码语言:javascript
复制
def get_streaks_rsi(self, closing_prices, length):
        # logic tables
        series = pd.DataFrame(closing_prices)
        geq = series >= series.shift(1)  # True if rising
        eq = series == series.shift(1)  # True if equal
        logic_table = pd.concat([geq, eq], axis=1)

        streaks = [0]  # holds the streak duration, starts with 0

        for row in logic_table.iloc[1:].itertuples():  # iterate through logic table
            if row[2]:  # same value as before
                streaks.append(0)
                continue
            last_value = streaks[-1]
            if row[1]:  # higher value than before
                streaks.append(last_value + 1 if last_value >= 0 else 1)  # increase or reset to +1
            else:  # lower value than before
                streaks.append(last_value - 1 if last_value < 0 else -1)  # decrease or reset to -1

        streaks_numpy = np.array(streaks, dtype=np.float)
        streaks_rsi = talib.RSI(streaks_numpy, length)
        return streaks_rsi[-1]

    def get_connors_rsi(self, a, b, c):
        candles = self.client.futures_klines(symbol=self.symbol,
                                             interval=self.candles_time,
                                             limit=1500)
        closing_prices = np.array([float(candle[4]) for candle in candles])

        first_rsi = self.get_rsi(closing_prices, a)
        print('RSI:', first_rsi)
        second_rsi = self.get_streaks_rsi(closing_prices, b)
        print('STREAKS:', second_rsi)
        third_rsi = self.get_percent_rank(closing_prices, c)
        print('PERCENT_RANK:', third_rsi)
        connors_rsi = (first_rsi + second_rsi + third_rsi) / 3
        print('CONNORS RSI:', connors_rsi)
        return connors_rsi
EN

回答 1

Stack Overflow用户

发布于 2022-05-18 09:30:44

我试过用你的密码。当您将“streaks_numpy”保存为talib将要使用的数据文件的一部分时,它似乎起作用了。我正在使用一个与塔利布非常相似的图书馆,这就是对我起作用的地方。当我运行你的密码时。

代码语言:javascript
复制
def get_streaks_rsi(closing_prices, length):
  # logic tables
  series = pd.DataFrame(closing_prices)
  geq = series >= series.shift(1)  # True if rising
  eq = series == series.shift(1)  # True if equal
  logic_table = pd.concat([geq, eq], axis=1)

  streaks = [0]  # holds the streak duration, starts with 0

  for row in logic_table.iloc[1:].itertuples():  # iterate through logic table
      if row[2]:  # same value as before
          streaks.append(0)
          continue
      last_value = streaks[-1]
      if row[1]:  # higher value than before
          streaks.append(last_value + 1 if last_value >= 0 else 1)  # increase or reset to +1
      else:  # lower value than before
          streaks.append(last_value - 1 if last_value < 0 else -1)  # decrease or reset to -1

  df['streaks_numpy'] = np.array(streaks, dtype=float)
  streaks_rsi = ta.momentum.rsi(df['streaks_numpy'], length)
  return streaks_rsi.iloc[-1]
get_streaks_rsi(df['Close'], 2)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71156895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档