【发布时间】:2021-10-13 06:59:13
【问题描述】:
如何仅使用 numpy 计算平均真实范围(ATR)?我更喜欢最快的方式。
Atr 计算:
熊猫和 Numpy:
import numpy as np
import pandas as pd
high_low = data['High'] - data['Low']
high_close = np.abs(data['High'] - data['Close'].shift())
low_close = np.abs(data['Low'] - data['Close'].shift())
ranges = pd.concat([high_low, high_close, low_close], axis=1)
true_range = np.max(ranges, axis=1)
atr = true_range.rolling(14).sum()/14
【问题讨论】:
-
您能否为
data数据框提供一些示例/虚拟值,以便我们运行您的代码?看到这个link on reproducible examples。
标签: python pandas numpy technical-indicator