Type/to search
1
Follow
2
Followers
求各位大佬能不能将这个代码转换为PANDAS的代码?
Help
Created 2021-06-29 21:03:55  
 1
 1255

这个是群主老大手写的开源的ATR函数,求各位大佬能部能写个PANDAS版本的,不使用TALIB功能

def ATR(records, period=14):
if len(records) == 0:
return []
if 'Close' not in records[0]:
raise "TA.ATR argument must KLine"

R = Std._zeros(len(records))
m = 0.0
n = 0.0
for i in xrange(0, len(records)):
TR = 0
if i == 0:
TR = records[i]['High'] - records[i]['Low']
else:
TR = max(records[i]['High'] - records[i]['Low'], abs(records[i]['High'] - records[i - 1]['Close']), abs(records[i - 1]['Close'] - records[i]['Low']))
m += TR
if i < period:
n = m / (i + 1)
else:
n = (((period - 1) * n) + TR) / period
R[i] = n
return R

Related Recommendations
Comment
All comments (1)

    速度没区别

    5 years ago
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)