Skip to content

Instantly share code, notes, and snippets.

@MaddoxRauch
Created February 24, 2022 03:50
Show Gist options
  • Save MaddoxRauch/b2182c250b6bf14000aaf2b682ace73a to your computer and use it in GitHub Desktop.
Save MaddoxRauch/b2182c250b6bf14000aaf2b682ace73a to your computer and use it in GitHub Desktop.
Simple Moving Average function
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