数据如下:
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)
使用你的值(value)观:
>>> (23.56333333 * 2 + 18.13) / 3
21.752222219999997
关于python - Python 的 talib.ATR 方法有错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66322638/