From 03306424418d6c8caf784fcf5155f0f8f817a4a9 Mon Sep 17 00:00:00 2001 From: fipelle <6272230+fipelle@users.noreply.github.com> Date: Sun, 17 Jul 2022 22:19:39 +0100 Subject: [PATCH 1/2] Added diff2 and diff_or_diff2 --- src/MessyTimeSeries.jl | 2 +- src/methods.jl | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/MessyTimeSeries.jl b/src/MessyTimeSeries.jl index 8a6fe1d..3c52362 100644 --- a/src/MessyTimeSeries.jl +++ b/src/MessyTimeSeries.jl @@ -20,7 +20,7 @@ module MessyTimeSeries # Export methods export check_bounds, nan_to_missing!, error_info, verb_message, interpolate_series, forward_backwards_rw_interpolation, centred_moving_average, soft_thresholding, solve_discrete_lyapunov, isconverged, trimmed_mean, sum_skipmissing, mean_skipmissing, std_skipmissing, is_vector_in_matrix, - demean, standardise, lag, companion_form, no_combinations, rand_without_replacement, get_bounded_log, get_unbounded_log, get_bounded_logit, get_unbounded_logit; + demean, standardise, diff2, diff_or_diff2, lag, companion_form, no_combinations, rand_without_replacement, get_bounded_log, get_unbounded_log, get_bounded_logit, get_unbounded_logit; # Export functions export kfilter!, kfilter_full_sample, kfilter_full_sample!, kforecast, ksmoother, fmin_uc_models, arima, varima, forecast, diff --git a/src/methods.jl b/src/methods.jl index 1dc90dc..f237296 100644 --- a/src/methods.jl +++ b/src/methods.jl @@ -353,6 +353,26 @@ standardise(X::FloatMatrix) = (X .- mean(X,dims=2))./std(X,dims=2); standardise(X::JVector{Float64}) = (X .- mean_skipmissing(X))./std_skipmissing(X); standardise(X::JMatrix{Float64}) = (X .- mean_skipmissing(X))./std_skipmissing(X); +""" + diff2(A::AbstractArray, dims::Integer) + +Return double-differenced data. +""" +diff2(A::AbstractArray; dims::Integer) = diff(diff(A, dims=dims), dims=dims); + +""" + diff_or_diff2(A::AbstractArray, dims::Integer, use_diff::Bool) + +Use either diff or diff2 depending on the value taken by `use_diff`. +""" +function diff_or_diff2(A::AbstractArray, dims::Integer, use_diff::Bool) + if use_diff + return diff(A, dims=dims); + else + return diff2(A, dims=dims); + end +end + """ interpolate_series(X::JMatrix{Float64}, n::Int64, T::Int64) From 20edac5678907e1b77763e704f5351939ebccbe7 Mon Sep 17 00:00:00 2001 From: Filippo Pellegrino <6272230+fipelle@users.noreply.github.com> Date: Sun, 17 Jul 2022 23:45:35 +0100 Subject: [PATCH 2/2] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 158795e..d26300c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "MessyTimeSeries" uuid = "2a88db5c-15f1-4b3e-a070-d1159e8d76cc" -version = "0.2.2" +version = "0.2.3" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"