【问题标题】:Python binance api rsi calculation with last 15 value is wrong最后 15 个值的 Python binance api rsi 计算是错误的
【发布时间】:2022-11-22 04:04:21
【问题描述】:

我想用 15 分钟的数据来计算我自己的 RSI 策略。我在 python 中使用 binance API。所以我需要 BTCUSDT 最近 15 次的收盘数据。我是这样理解的。

start = str(dt.datetime.now(dt.timezone.utc) - dt.timedelta(minutes=15*15))
end = str(dt.datetime.now())

trades = client.get_historical_klines(symbol='BTCUSDT',
                                      interval=Client.KLINE_INTERVAL_15MINUTE,
                                      start_str=start,
                                      end_str=end)

获取最后 15 个数据并计算 rsi 值,如下所示。

closes = [float(row[4]) for row in trades]
c = numpy.array(closes)

rsi = talib.RSI(c, timeperiod=14)

print(rsi[-1])

最后一个 RSI 的打印值与 binance 在线图表不同。例如,我的计算结果是 34.41,而 binance 网络应用程序显示图表上最新的 RSI 为 39.68,持续 15 分钟。

如果我计算初始 RSI 值,我将使用网络套接字将新的收盘价放入我的数组中。但这是错误的。我怎样才能做到这一点?

【问题讨论】:

    标签: python binance binance-api-client


    【解决方案1】:

    由于 Binance 与 Trading View 集成,因此应使用指数移动平均线 (EMA) 计算 rsi,而 talib 使用 SMMA(平滑移动平均线)。

    请注意,如果您使用更大的样本,您可能会发现差异更小(假设第一个柱为 0 增益和 0 损失将具有更小的权重)。

    如果您想详细了解,请参阅下面的 talib 代码:

    ta-lib : https://github.com/TA-Lib/ta-lib/blob/master/src/ta_func/ta_RSI.c

    如果您想使用 EMA 更改计算,请考虑以下代码: https://github.com/lukaszbinden/rsi_tradingview/blob/main/rsi.py

    【讨论】:

      猜你喜欢
      • 2021-09-08
      • 1970-01-01
      • 2023-03-13
      • 2016-11-23
      • 2022-08-12
      • 1970-01-01
      • 2018-07-23
      • 1970-01-01
      • 2020-10-07
      相关资源
      最近更新 更多