python - Python 的 talib.ATR 方法有错误吗?

标签 python ta-lib

数据如下:

high = np.array([10697.12, 10706.16, 10744.75, 10747.88, 10745.42])
low = np.array([10683.51, 10694.72, 10705.16, 10728.22, 10727.29])
close = np.array([10696.47, 10705.16, 10728.23, 10742.46, 10730.27])

方法一:直接将数据输入Average True Range方法

talib.ATR(high, low, close, timeperiod=3)
output: array([nan, nan, nan, 23.56333333, 21.75222222])

方法二:先计算True Range,再取平均值

talib.TRANGE(high, low, close)
output: array([nan, 11.44, 39.59, 19.66, 18.13])
taking 3 day average:
(11.44+39.59+19.66)/3=23.56
(39.59+19.66+18.13)/3=25.79

So the Average True Range array should be: array([nan, nan, nan, 23.56, 25.79])

第一种方法的平均真实范围数组中的最后一个值与第二种方法不同。 (21.75 比 25.79)

这里有什么问题吗?

最佳答案

talib.ATR()的计算是正确的。

来自Average true range page on Wikipedia :

The ATR at the moment of time t is calculated using the following formula: (This is one form of an exponential moving average)

ATR_{t}={{ATR_{{t-1}}\times (n-1)+TR_{t}} \over n}

使用你的值(value)观:

>>> (23.56333333 * 2 + 18.13) / 3
21.752222219999997

关于python - Python 的 talib.ATR 方法有错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66322638/

相关文章:

python - 如何判断光标的当前形状?

python - pandas 中 lambda 函数的正确使用

python - TA-Lib 如何识别十字星

c++ - 如何在代码块(Ubuntu 14.04)中链接 ta-lib?

python - 从 MySQL 到 CSV 格式

python - 在 PDF Django Weasyprint 中附加 img 文件

python - 如何将python脚本作为linux命令运行

python - 如何在航拍图像中检测白雪皑皑的背景上的黑色湖泊?

python - Python 的字符串连接与 str.join 相比有多慢?