Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ wma(x::Array{T}; n::Int64=10, wts::Array{T}=collect(1:n)/sum(1:n))::Array{Float6

Weighted moving average (WMA)
"""
function wma(x::AbstractArray{T}; n::Int64=10, wts::AbstractArray{T}=collect(1:n)/sum(1:n)) where {T<:Real}
function wma(x::AbstractArray{<:Real}; n::Int64=10, wts::AbstractArray{<:Real}=collect(1:n)/sum(1:n))
@assert n<size(x,1) && n>0 "Argument n out of bounds"
out = fill(NaN, size(x,1))
@inbounds for i = n:size(x,1)
Expand Down
5 changes: 5 additions & 0 deletions test/ma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,9 @@
@test size(tmp, 1) == N
@test size(tmp, 2) == 1
end
@testset "wma" begin
@test isequal(wma(ones(Real, 4); n=2, wts=fill(0.5, 2)), [NaN, 1, 1, 1])
@test isequal(wma(ones(Float64, 4); n=2, wts=fill(0.5, 2)), [NaN, 1, 1, 1])
@test isequal(wma(ones(Int64, 4); n=2, wts=ones(Float64, 2)), [NaN, 2, 2, 2])
end
end