Skip to content

Commit 1543a0b

Browse files
committed
tests passing with new running quantile function
1 parent cb0db45 commit 1543a0b

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/run.jl

+8-9
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,19 @@ Compute the running/rolling quantile of an array.
294294
295295
`runquantile(x::Vector{Float64}; p::Float64=0.05, n::Int=10, cumulative::Bool=true)::Vector{Float64}`
296296
"""
297-
function runquantile(x::Vector{Float64}; p::Float64=0.05, n::Int=10, cumulative::Bool=true)::Vector{Float64}
297+
function runquantile(x::Array{Float64}; p::Float64=0.05, n::Int=10, cumulative::Bool=true)::Array{Float64}
298298
@assert n<size(x,1) && n>1 "Argument n is out of bounds."
299-
N = length(x)
300-
out = zeros(Float64, length(x))
299+
out = zeros(Float64, (size(x,1), size(x,2)))
301300
if cumulative
302-
@inbounds for i in 2:N
303-
out[i] = quantile(x[1:i], p)
301+
@inbounds for j in 1:size(x,2), i in 2:size(x,1)
302+
out[i,j] = quantile(x[1:i,j], p)
304303
end
305-
out[1] = NaN
304+
out[1,:] = NaN
306305
else
307-
@inbounds for i in n:N
308-
out[i] = quantile(x[i-n+1:i], p)
306+
@inbounds for j in 1:size(x,2), i in n:size(x,1)
307+
out[i,j] = quantile(x[i-n+1:i,j], p)
309308
end
310-
out[1:n-1] = NaN
309+
out[1:n-1,:] = NaN
311310
end
312311
return out
313312
end

src/temporal.jl

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ runvar{V,T}(X::TS{V,T}; args...) = close_fun(X, runvar, [:RunVar]; args...)
4646
runmax{V,T}(X::TS{V,T}; args...) = close_fun(X, runmax, [:RunMax]; args...)
4747
runmin{V,T}(X::TS{V,T}; args...) = close_fun(X, runmin, [:RunMin]; args...)
4848
runsd{V,T}(X::TS{V,T}; args...) = close_fun(X, runsd, [:RunSD]; args...)
49+
runquantile{V,T}(X::TS{V,T}; args...) = close_fun(X, runquantile, [:RunQuantile]; args...)
4950
wilder_sum{V,T}(X::TS{V,T}; args...) = close_fun(X, wilder_sum, [:WilderSum]; args...)
5051

5152
##### ma.jl ######

test/runtests.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ end
439439
@test size(tmp, 1) == N
440440
@test size(tmp, 2) == 1
441441
tmp = runquantile(x, cumulative=true)
442-
@test !isnan(tmp[2,:]) && isnan(tmp[1,:])
443-
@test tmp[10,1] = quantile(x[1:10], 0.05)
442+
@test !isnan(tmp.values[2,1]) && isnan(tmp.values[1,1])
443+
@test tmp.values[10,1] == quantile(x.values[1:10,1], 0.05)
444444
tmp = runquantile(x, cumulative=false)
445-
@test tmp[10,1] = quantile(x[1:10], 0.05)
445+
@test tmp.values[10,1] == quantile(x.values[1:10,1], 0.05)
446446
# moving average functions
447447
tmp = sma(x)
448448
@test size(tmp, 1) == N

0 commit comments

Comments
 (0)