Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,24 @@
|
|||
local fmt = require "fmt"
|
||||
|
||||
local function sma(period)
|
||||
local i = 0
|
||||
local sum = 0
|
||||
local storage = {}
|
||||
return function(input)
|
||||
if #storage < period then
|
||||
sum += input
|
||||
storage:insert(input)
|
||||
end
|
||||
sum += input - storage[i + 1]
|
||||
storage[i + 1] = input
|
||||
i = (i + 1) % period
|
||||
return sum / #storage
|
||||
end
|
||||
end
|
||||
|
||||
local sma3 = sma(3)
|
||||
local sma5 = sma(5)
|
||||
print(" x sma3 sma5")
|
||||
for {1, 2, 3, 4, 5, 5, 4, 3, 2, 1} as x do
|
||||
fmt.print("%5.3f %5.3f %5.3f", x, sma3(x), sma5(x))
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue