Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
T SMA
|
||||
[Float] data
|
||||
sum = 0.0
|
||||
index = 0
|
||||
n_filled = 0
|
||||
Int period
|
||||
|
||||
F (period)
|
||||
.period = period
|
||||
.data = [0.0] * period
|
||||
|
||||
F add(v)
|
||||
.sum += v - .data[.index]
|
||||
.data[.index] = v
|
||||
.index = (.index + 1) % .period
|
||||
.n_filled = min(.period, .n_filled + 1)
|
||||
R .sum / .n_filled
|
||||
|
||||
V sma3 = SMA(3)
|
||||
V sma5 = SMA(5)
|
||||
|
||||
L(e) [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]
|
||||
print(‘Added #., sma(3) = #.6, sma(5) = #.6’.format(e, sma3.add(e), sma5.add(e)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue