1
집중하다
2
수행원

이 코드를 PANDAS 코드로 변환해 주시겠습니까?

만든 날짜: 2021-06-29 21:03:55, 업데이트 날짜:
comments   1
hits   978

이 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