Last active
February 10, 2021 04:55
-
-
Save dharma6872/90b463724a9af0f2aa759a6cef8e5687 to your computer and use it in GitHub Desktop.
[이동평균] #권트
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 파라미터 | |
# 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