Skip to content

Instantly share code, notes, and snippets.

@sduff
Created May 17, 2023 09:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sduff/0c1295f3b039c6da98a5b7249e6bbdc3 to your computer and use it in GitHub Desktop.
Save sduff/0c1295f3b039c6da98a5b7249e6bbdc3 to your computer and use it in GitHub Desktop.
Rolling Moving Average
def r(new_value, old_values):
if len(old_values) > 10:
old_values.pop(0)
old_values.append(new_value)
average = sum(old_values) / len(old_values)
return average, old_values
history = []
for i in range(100):
value, history = r(i, history)
print(value, history)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment