d4ca9c4620
Move the SMA implementation from examples/err.myc and examples/sma.myc to a new dedicated file in lib/. This change also cleans up unused code and improves the SMA logic.
21 lines
450 B
Plaintext
21 lines
450 B
Plaintext
(do
|
|
(def SMA
|
|
(fn [length]
|
|
(do
|
|
(def history (series :float))
|
|
(def sum 0.0)
|
|
|
|
(fn [val]
|
|
(do
|
|
(def hist_len (len history))
|
|
(if (>= hist_len length)
|
|
(assign sum (- sum (history (- length 1)))))
|
|
|
|
(push history val)
|
|
(assign sum (+ sum val))
|
|
|
|
(if (>= hist_len length)
|
|
(/ sum length))
|
|
)))))
|
|
)
|