TimeSeriesUtils.ARMAacf — Function
ARMAacf(; ϕ, θ, maxlag, pacf)Compute the Autocorrelation function (ACF) or partial ACF (PACF, if pacf == true) for an ARMA process for the lags k = 1,2,...,maxlag.
Examples
julia> acf = ARMAacf(ϕ = [0.8], θ = [0.0], maxlag = 10, pacf = false);
julia> bar(0:10, acf)TimeSeriesUtils.arma_reparam — Function
arma_reparam(x::Vector [, pacf_map = "monahan", negative_signs = true])Takes a p-dim vector x and returns parameters restricted to the have roots outside the unit circle, i.e. stationary(AR) or invertible (MA). The mapping is performed via the partial autocorrelations, P as: x -> P -> ϕ.
If pacf_map == "tanh", then the partial autocorrelations are parameterized as P = tanh(x)
If pacf_map == "monahan", then the partial autocorrelations are parameterized as P = x/√(1 + x²)
If pacf_map == "hardtanh", then the partial autocorrelations are parameterized as hardtanh
If negative_signs == true coefficients are for polynomial 1 - ϕ₁B - ϕ₂B² - .... which is typically used for AR
If negative_signs == false coefficients are for polynomial 1 + ϕ₁B + ϕ₂B² + .... which is typically used for MA
Examples
julia> ϕ, partials = arma_reparam([-4.0,4.0]; pacf_map = "monahan");ϕ
2-element Vector{Float64}:
-0.028966029557096595
0.9701425001453319
julia> check_stationarity(ϕ)[1] # second element would return the eigenvalues
trueTimeSeriesUtils.inv_arma_reparam — Function
inv_arma_reparam(ϕ; pacf_map = "monahan")Converts from some AR parameters down to the unrestricted parameters. This inverts numerically, so inefficient.
TimeSeriesUtils.check_stationarity — Function
check_stationarity(ϕ::Vector)Test if the AR(p) polynomial 1 - ϕ₁B - ϕ₂B² - ... - ϕₚB^p corresponding to ϕ has all roots outside the unit circle, i.e. if the AR(p) process is stationary.
Returns a tuple where first element is true if stationary. Second element is a vector with the eigenvalues to the companion matrix.
Examples
julia> ϕ, P = arma_reparam([-4,4]; pacf_map = "monahan") # returns ϕ which is stationary.
2-element Vector{Float64}:
-0.028966029557096595
0.9701425001453319
julia> check_stationarity(ϕ)[1]
trueTimeSeriesUtils.sim_uniformAR — Function
Simulate from a uniform prior for AR(p) over stationary region by simulating partials.TimeSeriesUtils.sarma_reparam — Function
sarma_reparam(θ::Vector, Θ::Vector, s, activeLags; pacf_map = "monahan", negative_signs = true)Takes a p-dim vector θ with regular AR/MA coefficients and a P-dim vector with seasonal AR/MA coefficients Θ (with season s) and returns the non-zero coefficients in the product polynomial (1 - ϕ₁B - ϕ₂B² - ....)(1 - Φ₁B - Φ₂B² - ....) = (1 - ψ₁B - Ψ₂B² - ....) where both sets of parameters (ϕ and Φ) are restricted to the have roots outside the unit circle, i.e. stationary(AR) or invertible (MA). The mapping is performed via the partial autocorrelations, P as: θ -> P₁ -> ϕ and Θ -> P₂ -> Φ.
If pacf_map == "tanh", then the partial autocorrelations are parameterized as P = (exp(x) - 1) / (exp(x) + 1 )
If pacf_map == "monahan", then the partial autocorrelations are parameterized as P = x/√(1 + x²)
If negative_signs == true coefficients are for polynomial 1 - ϕ₁B - ϕ₂B² - .... which is typically used for AR
If negative_signs == false coefficients are for polynomial 1 + ϕ₁B + ϕ₂B² + .... which is typically used for MA
TimeSeriesUtils.Arima — Function
Arima(y; order = [0,0,0], seasonal = [0,0,0], xreg = nothing, include_mean = true,
include_drift = false, include_constant = true, frequency = 1, deltat = 1)R function that estimates an ARIMA model for the time series y.
TimeSeriesUtils.simARMA — Function
simARMA(ϕ, θ, c, σ, T)Simulate a time series of length T from the univariate ARMA process with the vector of AR coefficients ϕ, vector of MA coefficients θ, constant (intercept) c and innovation standard deviation σ:
\[x_t = c + \sum_{j=1}^p \phi_j x_{t-j} + \sum_{k=1}^q \theta_k a_{t-k} \]
Uses the ARCHModels.jl package.
Examples
Simulate T=5 observations from the ARMA(1,1) process:
julia> simARMA([0.7], [0.3], 0.0, 1.0, 5)
5-element Vector{Float64}:
0.30639811188691285
0.8315918084473066
1.1336754037240127
-0.15634038037829656
-0.3521705897607527TimeSeriesUtils.ℓARMA — Function
ℓARMA(data::Vector, ϕ, θ, c, σ)Compute the time domain likelihood of the data in the univariate ARMA process with the vector of AR coefficients ϕ, vector of MA coefficients θ, constant (intercept) c and innovation standard deviation σ:
\[x_t = c + \sum_{j=1}^p \phi_j x_{t-j} + \sum_{k=1}^q \theta_k a_{t-k} \]
Uses the ARCHModels.jl package.
Examples
log-likelihood for a time series with 5 observeration in the AR(1) process with ϕ = 0.8, c = 0, σ = 1:
julia> ℓARMA([1.1,2.2,1.7,1.9,2.3], [0.8], [0.0], 0.0, 1.0)
-6.191492666023364TimeSeriesUtils.SpecDensARMA — Function
SpecDensARMA(ω, ϕ, θ, σ²)Compute spectral density for the univariate ARMA model over domain ω ∈ [-π,π].
- ω is a radial frequency
- ϕ is a vector of AR coefficients
- θ is a vector of MA coefficients
- σ² is the noise variance
Examples
The spectral density for an AR(1) process with unit noise variance is
julia> SpecDensARMA(0.5, 0.9, 0, 1)
0.6909224383713601TimeSeriesUtils.SpecDensSARMA — Function
SpecDensSARMA(ω, ϕ, θ, Φ, Θ, σ², s)Compute spectral density for the seasonal univariate ARMA model over domain ω ∈ [-π,π].
- ω is a radial frequency
- ϕ is a vector of AR coefficients
- θ is a vector of MA coefficients
- Φ is a vector of seasonal AR coefficients
- Θ is a vector of seasonal MA coefficients
- σ² is the noise variance
- s is the seasonality (e.g. s = 12 for monthly data)
Examples
The spectral density for an AR(2)(1)₄ process with unit noise variance is
julia> SpecDensSARMA(0.5, [0.8,-0.2], 0, 0.6, 0, 1, 4)
0.4053556832813598TimeSeriesUtils.SpecDensMultiSARMA — Function
SpecDensMultiSARMA(ω, ϕ, θ, σ², s)Compute spectral density for the multi-seasonal univariate ARMA model over domain ω ∈ [-π,π]. ω can be a scalar or a vector.
- ω is a radial frequency
- ϕ is a vector of of vectors where ϕ[l] are the AR coefficients in l:th polynomial
- θ is a vector of of vectors where θ[l] are the MA coefficients in l:th polynomial empty vector in ϕ means that that specific polynomial is not present in AR. Same for θ.
- σ² is the noise variance
- s is the seasonality (e.g. s = (1,4,12) for regular, quarterly and monthly seasons)
Examples
The spectral density at ω = 0.5 for an SAR(p = (2,1), q = (0,0),s=(1,4)) process with unit noise variance is
julia> SpecDensMultiSARMA(0.5, [[0.8,-0.2],[0.6]], [[],[]], 1, [2,1], [0,0], [1 4])TimeSeriesUtils.SpecDensARTFIMA — Function
SpecDensARTFIMA(ω, ϕ, θ, d, λ, σ²)Compute spectral density for the univariate ARTFIMA model over domain ω ∈ [-π,π].
- ω is a radial frequency
- ϕ is a vector of AR coefficients
- θ is a vector of MA coefficients
- d is the fractional differenting parameter
- λ ≥ 0 is the tempering parameter
- σ² is the noise variance
Examples
The spectral density for an AR(1) process with unit noise variance is
julia> SpecDensARTFIMA(0.5, 0.9, 0, 0, 0, 1)
0.6909224383713601TimeSeriesUtils.hardtanh — Function
hardtanh(x, ε = 0.0001)Hard tanh function that maps x linearly to the interval (-1 + ε, 1 - ε).
Examples
julia> hardtanh(0.4, 0.0001)
0.4
julia> hardtanh(1, 0.0001)
0.9999
julia> hardtanh(-1.1, 0.0001)
-0.9999