Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,28 @@
import deques
proc simplemovingaverage(period: int): auto =
assert period > 0
var
summ, n = 0.0
values: Deque[float]
for i in 1..period:
values.addLast(0)
proc sma(x: float): float =
values.addLast(x)
summ += x - values.popFirst()
n = min(n+1, float(period))
result = summ / n
return sma
var sma = simplemovingaverage(3)
for i in 1..5: echo sma(float(i))
for i in countdown(5,1): echo sma(float(i))
echo ""
var sma2 = simplemovingaverage(5)
for i in 1..5: echo sma2(float(i))
for i in countdown(5,1): echo sma2(float(i))