Skip to content

Commit

Permalink
temporal ts object support and robustness fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dysonance committed Jul 6, 2018
1 parent e3226b9 commit fe74ad7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/temporal.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Methods for porting Indicators.jl functions to TS objects from Temporal.jl package
function close_fun(X::TS, f::Function, flds::Vector{Symbol}; args...)
function close_fun(X::TS, f::Function, flds::Vector{Symbol}=[]; args...)
if size(X,2) == 1
return ts(f(X.values; args...), X.index, flds)
elseif size(X,2) > 1 && has_close(X)
return ts(f(cl(X).values; args...), X.index, flds)
if length(flds) == 0
return ts(f(cl(X).values; args...), X.index)
else
return ts(f(cl(X).values; args...), X.index, flds)
end
else
error("Must be univariate or contain Close/Settle/Last.")
end
Expand Down Expand Up @@ -48,6 +52,8 @@ runmin{V,T}(X::TS{V,T}; args...) = close_fun(X, runmin, [:RunMin]; args...)
runsd{V,T}(X::TS{V,T}; args...) = close_fun(X, runsd, [:RunSD]; args...)
runquantile{V,T}(X::TS{V,T}; args...) = close_fun(X, runquantile, [:RunQuantile]; args...)
wilder_sum{V,T}(X::TS{V,T}; args...) = close_fun(X, wilder_sum, [:WilderSum]; args...)
runacf{V,T}(X::TS{V,T}; n::Int=10, maxlag::Int=n-3, lags::AbstractArray{Int,1}=0:maxlag, cumulative::Bool=true) =
close_fun(X, runacf, [Symbol(i) for i in lags]; n=n, maxlag=maxlag, lags=lags, cumulative=cumulative)

##### ma.jl ######
sma{V,T}(X::TS{V,T}; args...) = close_fun(X, sma, [:SMA]; args...)
Expand Down
9 changes: 5 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,11 @@ end
@test tmp.values[10,1] == quantile(x.values[1:10,1], 0.05)
tmp = runquantile(x, cumulative=false)
@test tmp.values[10,1] == quantile(x.values[1:10,1], 0.05)
tmp = runacf(x, n=20, maxlag=15, cumulative=true)
@test all(tmp[10:end,1] .== 1.0)
tmp = runacf(x, n=20, maxlag=15, cumulative=false)
@test all(tmp[10:end,1] .== 1.0)
n = 20
tmp = runacf(x, n=n, maxlag=15, cumulative=true)
@test all(tmp.values[n:end,1] .== 1.0)
tmp = runacf(x, n=n, maxlag=15, cumulative=false)
@test all(tmp.values[n:end,1] .== 1.0)
# moving average functions
tmp = sma(x)
@test size(tmp, 1) == N
Expand Down

0 comments on commit fe74ad7

Please sign in to comment.