From ee3662b2d42f2ff3da0c042b5b30a1256ff4a925 Mon Sep 17 00:00:00 2001 From: Iblis Lin Date: Sun, 14 May 2017 16:22:59 +0800 Subject: [PATCH 1/2] kama: accept integer TimeArray close #83 --- src/movingaverages.jl | 11 +++++++++-- test/movingaverages.jl | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/movingaverages.jl b/src/movingaverages.jl index 745a9e8..5f73eb2 100644 --- a/src/movingaverages.jl +++ b/src/movingaverages.jl @@ -56,7 +56,7 @@ function kama{T,N}(ta::TimeArray{T,N}, n::Int=10, fn::Int=2, sn::Int=30) sc = (er .* (2 / (fn + 1) - 2 / (sn + 1)) .+ 2 / (sn + 1)).^2 cl = ta[n+1:end] - vals = similar(cl.values) + vals = similar(Array{Float64}, indices(cl.values)) # using simple moving average as initial kama pri_kama = mean(ta[1:n].values, 1) @@ -68,7 +68,14 @@ function kama{T,N}(ta::TimeArray{T,N}, n::Int=10, fn::Int=2, sn::Int=30) pri_kama .+ sc[idx].values .* (cl[idx].values .- pri_kama) end - TimeArray(cl.timestamp, vals, ["$c\_kama" for c in ta.colnames]) + cols = + if length(ta.colnames) == 1 + ["kama"] + else + ["$c\_kama" for c in ta.colnames] + end + + TimeArray(cl.timestamp, vals, cols) end # Array dispatch for use by other algorithms diff --git a/test/movingaverages.jl b/test/movingaverages.jl index bad6533..33ad76c 100644 --- a/test/movingaverages.jl +++ b/test/movingaverages.jl @@ -53,10 +53,14 @@ facts("Moving averages on TimeArrays") do @fact ta.values[2] --> roughly(99.0098, atol=.01) @fact ta.values[3] --> roughly(99.4499, atol=.01) @fact ta.timestamp[1] --> Date(2000, 1, 18) + @fact ta.colnames --> ["kama"] ta = kama(ohlc) @fact length(ta.colnames) --> 4 @fact ta.timestamp[1] --> Date(2000, 1, 18) + + ta = kama(TimeArray(collect(Date(2011, 1, 1):Date(2011, 1, 20)), 1:20)) + @fact ta.timestamp[end] --> Date(2011, 1, 20) end end From 34cd3f50bfd584d42ec32474d6698a868291c248 Mon Sep 17 00:00:00 2001 From: Iblis Lin Date: Sun, 14 May 2017 16:23:59 +0800 Subject: [PATCH 2/2] update news for #83 --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 9b12045..c77a9a9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ ### 0.6.0 * New indicator: - * Kaufman's Adaptive Moving Average (issue #76) + * Kaufman's Adaptive Moving Average (issue #76, #83) * doc: migrate to `Documenter.jl`, and the online doc is available at github pages. (issue #63, #58, #69)