Created
February 24, 2022 03:50
-
-
Save MaddoxRauch/b2182c250b6bf14000aaf2b682ace73a to your computer and use it in GitHub Desktop.
Simple Moving Average function
This file contains hidden or 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
def sma(items: list, window: int = 5) -> list: | |
"""Simple moving average for list. Window is the amount to average.""" | |
count = 0 | |
averages = [] | |
while count < len(items) - window + 1: | |
values = items[count: count + window] | |
avg = int(sum(values)/window) | |
averages.append(avg) | |
count += 1 | |
return averages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment