Skip to content

Instantly share code, notes, and snippets.

@dharma6872
Last active February 10, 2021 04:55
Show Gist options
  • Save dharma6872/90b463724a9af0f2aa759a6cef8e5687 to your computer and use it in GitHub Desktop.
Save dharma6872/90b463724a9af0f2aa759a6cef8e5687 to your computer and use it in GitHub Desktop.
[이동평균] #권트
# 파라미터
# Data: 데이터(np.array), lookback: 이동 평균 기간(int), what: 대상 데이터 위치(int), where: 저장할 위치(int)
# ma: moving average
def ma(Data, lookback, what, where):
for i in range(len(Data)):
try:
Data[i, where] = (Data[i - lookback + 1:i + 1, what].mean())
except IndexError:
pass
return Data
# 사용 예시
# ma(대상 데이터, 이동평균 기간, 소스 칼럼, 타겟 칼럼)
# ma(ma_data, 100, CLOSE, MEAN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment