Forecasting Long Memory Processes
Functions to forecast long memory processes using the fractional differencing operator and the cross-sectional aggregation method. Forecasting using the HAR model is also available.
LongMemory.Forecasters — Module
Forecasters
This module contains functions to forecast a long memory time series using the fractional differencing method and the CSA method.
Author
LongMemory.Forecasters.arfima_ar_coefs — Method
arfima_ar_coefs(d::Real, AR::AbstractArray, MA::AbstractArray, maxlags::Int)Computes the AR(∞) coefficients of the ARFIMA(p,d,q) model at lags 1, ..., maxlags.
Arguments
d::Real: The fractional differencing parameter.AR::Array: The AR coefficients.MA::Array: The MA coefficients.maxlags::Int: The number of lags to compute.
Output
ar_coefs::Array: The coefficientsπ_jinx_t = Σ_j π_j x_{t-j} + ε_t, at lags 1, ...,maxlags.
Notes
The coefficients are those of 1 - φ(L)(1-L)^d / θ(L). They are computed by multiplying the polynomials and dividing by θ(L) recursively. With AR = MA = [] they coincide with fi_ar_coefs.
Examples
julia> arfima_ar_coefs(0.2, [0.5], [0.3], 5)LongMemory.Forecasters.arfima_forecast — Method
arfima_forecast(x::AbstractArray, h::Int, d::Real, AR::AbstractArray, MA::AbstractArray, σ::Real)Computes the forecast of a time series using the ARFIMA(p,d,q) model, with confidence bands.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.d::Real: The fractional differencing parameter.AR::Array: The AR coefficients.MA::Array: The MA coefficients.σ::Real: The standard deviation of the innovations.
Output
xfor::Array: The forecast of the time series as a matrix where the first column is the forecast, the second column is the lower confidence band, and the third column is the upper confidence band. The first T elements are the original time series.
Notes
Multiple dispatch is used to compute the forecast of a time series with or without confidence bands. The bands are the forecast ± 2 standard errors of the k-step forecast error, σ (ψ₀² + ... + ψ_{k-1}²)^{1/2}, where ψ are the MA coefficients from arfima_ma_coefs.
Examples
julia> arfima_forecast(arfima_gen(100, 0, [0.5], 0.2, []), 10, 0.2, [0.5], [], 1.0)LongMemory.Forecasters.arfima_forecast — Method
arfima_forecast(x::AbstractArray, h::Int, d::Real, AR::AbstractArray, MA::AbstractArray)Computes the forecast of a time series using the ARFIMA(p,d,q) model.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.d::Real: The fractional differencing parameter.AR::Array: The AR coefficientsφ, with the AR polynomial1 - φ₁L - ... - φₚLᵖ.MA::Array: The MA coefficientsθ, with the MA polynomial1 + θ₁L + ... + θ_qL^q.
Output
xfor::Array: The forecast of the time series as a vector. The first T elements are the original time series.
Notes
Multiple dispatch is used to compute the forecast of a time series with or without confidence bands. The forecasts use the AR(∞) representation of the model, φ(L)(1-L)^d / θ(L), truncated at the start of the sample, see arfima_ar_coefs. With AR = MA = [] they coincide with fi_forecast. The series is demeaned with the sample mean before forecasting and the mean is added back to the forecasts. The parametrization is the one used by arfima_gen and arfima_whittle_est.
Examples
julia> arfima_forecast(arfima_gen(100, 0, [0.5], 0.2, []), 10, 0.2, [0.5], [])LongMemory.Forecasters.arfima_forecast_plot — Method
arfima_forecast_plot(x::AbstractArray, h::Int, d::Real, AR::AbstractArray, MA::AbstractArray, σ::Real)Plots the forecast of a time series using the ARFIMA(p,d,q) model, with confidence bands.
Requires Plots.jl to be loaded, e.g. with using LongMemory, Plots.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.d::Real: The fractional differencing parameter.AR::Array: The AR coefficients.MA::Array: The MA coefficients.σ::Real: The standard deviation of the innovations.
Output
p1::Plot: The plot of the original time series and the forecast with confidence bands.
Notes
Multiple dispatch is used to plot the forecast of a time series with or without confidence bands. Plotting is done by calling the arfima_forecast function.
Examples
julia> arfima_forecast_plot(arfima_gen(100, 0, [0.5], 0.2, []), 10, 0.2, [0.5], [], 1.0)LongMemory.Forecasters.arfima_forecast_plot — Method
arfima_forecast_plot(x::AbstractArray, h::Int, d::Real, AR::AbstractArray, MA::AbstractArray)Plots the forecast of a time series using the ARFIMA(p,d,q) model.
Requires Plots.jl to be loaded, e.g. with using LongMemory, Plots.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.d::Real: The fractional differencing parameter.AR::Array: The AR coefficients.MA::Array: The MA coefficients.
Output
p1::Plot: The plot of the original time series and the forecast.
Notes
Multiple dispatch is used to plot the forecast of a time series with or without confidence bands. Plotting is done by calling the arfima_forecast function.
Examples
julia> arfima_forecast_plot(arfima_gen(100, 0, [0.5], 0.2, []), 10, 0.2, [0.5], [])LongMemory.Forecasters.arfima_ma_coefs — Method
arfima_ma_coefs(d::Real, AR::AbstractArray, MA::AbstractArray, maxlags::Int)Computes the MA(∞) coefficients of the ARFIMA(p,d,q) model at lags 0, ..., maxlags-1.
Arguments
d::Real: The fractional differencing parameter.AR::Array: The AR coefficients.MA::Array: The MA coefficients.maxlags::Int: The number of lags to compute.
Output
ma_coefs::Array: The coefficients ofθ(L)(1-L)^{-d} / φ(L)at lags 0, ...,maxlags-1.
Notes
The zero lag coefficient is included, it is 1. With AR = MA = [] they coincide with fi_ma_coefs.
Examples
julia> arfima_ma_coefs(0.2, [0.5], [0.3], 5)LongMemory.Forecasters.csa_forecast — Method
csa_forecast(x::AbstractArray, h::Int, p::Real, q::Real, σ::Real)Computes the forecast of a long memory time series using the CSA method.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.p::Real: The parameter p of the CSA process.q::Real: The parameter q of the CSA process.σ::Real: The standard deviation of the innovations.
Output
xfor::Array: The forecast of the time series as a matrix where the first column is the forecast, the second column is the lower confidence band, and the third column is the upper confidence band. The first T elements are the original time series.
Notes
Multiple dispatch is used to compute the forecast of a time series with or without confidence bands. The bands are the forecast ± 2 standard errors of the k-step forecast error, σ (ψ₀² + ... + ψ_{k-1}²)^{1/2}, where ψ are the MA coefficients from csa_ma_coefs. Hence, they widen with the horizon.
Examples
julia> csa_forecast(csa_gen(100,1.4,1.4), 10, 1.4, 1.4, 1.0)LongMemory.Forecasters.csa_forecast — Method
csa_forecast(x::AbstractArray, h::Int, p::Real, q::Real)Computes the forecast of a long memory time series using the CSA method.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.p::Real: The parameter p of the CSA process.q::Real: The parameter q of the CSA process.
Output
xfor::Array: The forecast of the time series as a vector. The first T elements are the original time series.
Notes
Multiple dispatch is used to compute the forecast of a time series with or without confidence bands. The series is demeaned with the sample mean before forecasting and the mean is added back to the forecasts.
Examples
julia> csa_forecast(csa_gen(100,1.4,1.4), 10, 1.4, 1.4)LongMemory.Forecasters.csa_forecast_plot — Method
csa_forecast_plot(x::AbstractArray, h::Int, p::Real, q::Real, σ::Real)Plots the forecast of a long memory time series using the CSA method.
Requires Plots.jl to be loaded, e.g. with using LongMemory, Plots.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.p::Real: The parameter p of the CSA process.q::Real: The parameter q of the CSA process.σ::Real: The standard deviation of the innovations.
Output
p1::Plot: The plot of the original time series and the forecast with confidence bands.
Notes
Multiple dispatch is used to plot the forecast of a time series with or without confidence bands. Plotting is done by calling the csa_forecast function.
Examples
julia> csa_forecast_plot(csa_gen(100,1.4,1.4), 10, 1.4, 1.4, 1.0)LongMemory.Forecasters.csa_forecast_plot — Method
csa_forecast_plot(x::AbstractArray, h::Int, p::Real, q::Real)Plots the forecast of a long memory time series using the CSA method.
Requires Plots.jl to be loaded, e.g. with using LongMemory, Plots.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.p::Real: The parameter p of the CSA process.q::Real: The parameter q of the CSA process.
Output
p1::Plot: The plot of the original time series and the forecast.
Notes
Multiple dispatch is used to plot the forecast of a time series with or without confidence bands. Plotting is done by calling the csa_forecast function.
Examples
julia> csa_forecast_plot(csa_gen(100,1.4,1.4), 10, 1.4, 1.4)LongMemory.Forecasters.csa_ma_coefs — Method
csa_ma_coefs(p::Real, q::Real, maxlags::Int)Computes the MA coefficients of the CSA process with parameters p and q at lags 0, ..., maxlags-1.
Arguments
p::Real: The parameter p of the CSA process.q::Real: The parameter q of the CSA process.maxlags::Int: The number of lags to compute.
Output
ma_coefs::Array: The MA coefficients of the CSA process with parameterspandqat lags 0, ...,maxlags-1.
Notes
The MA coefficients are computed using the recursive formula for speed. The zero lag coefficient is included, it is theoretically 1.
Examples
julia> csa_ma_coefs(1.4, 1.4, 5)LongMemory.Forecasters.fi_ar_coefs — Method
fi_ar_coefs(d::Real, maxlags::Int)Computes the AR coefficients of the fractional differenced process with parameter d at lags 1, ..., maxlags.
Arguments
d::Real: The fractional differencing parameter.maxlags::Int: The number of lags to compute.
Output
ar_coefs::Array: The AR coefficients of the fractional differenced process with parameterdat lags 1, ...,maxlags.
Notes
The AR coefficients are computed using the recursive formula for speed. The zero lag coefficient is not computed, it is theoretically 1.
Examples
julia> fi_ar_coefs(0.2, 5)LongMemory.Forecasters.fi_forecast — Method
fi_forecast(x::AbstractArray, h::Int, d::Real, σ::Real)Computes the forecast of a long memory time series using the fractional differencing method.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.d::Real: The fractional differencing parameter.σ::Real: The standard deviation of the innovations.
Output
xfor::Array: The forecast of the time series as a matrix where the first column is the forecast, the second column is the lower confidence band, and the third column is the upper confidence band. The first T elements are the original time series.
Notes
Multiple dispatch is used to compute the forecast of a time series with or without confidence bands. The bands are the forecast ± 2 standard errors of the k-step forecast error, σ (ψ₀² + ... + ψ_{k-1}²)^{1/2}, where ψ are the MA coefficients from fi_ma_coefs. Hence, they widen with the horizon.
Examples
julia> fi_forecast(fi_gen(100,0.2), 10, 0.2, 1.0)LongMemory.Forecasters.fi_forecast — Method
fi_forecast(x::AbstractArray, h::Int, d::Real)Computes the forecast of a long memory time series using the fractional differencing method.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.d::Real: The fractional differencing parameter.
Output
xfor::Array: The forecast of the time series as a vector. The first T elements are the original time series.
Notes
Multiple dispatch is used to compute the forecast of a time series with or without confidence bands. The series is demeaned with the sample mean before forecasting and the mean is added back to the forecasts.
Examples
julia> fi_forecast(fi_gen(100,0.2), 10, 0.2)LongMemory.Forecasters.fi_forecast_plot — Method
fi_forecast_plot(x::AbstractArray, h::Int, d::Real, σ::Real)Plots the forecast of a long memory time series using the fractional differencing method.
Requires Plots.jl to be loaded, e.g. with using LongMemory, Plots.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.d::Real: The fractional differencing parameter.σ::Real: The standard deviation of the innovations.
Output
p1::Plot: The plot of the original time series and the forecast with confidence bands.
Notes
Multiple dispatch is used to plot the forecast of a time series with or without confidence bands. Plotting is done by calling the fi_forecast function.
Examples
julia> fi_forecast_plot(fi_gen(100,0.2), 10, 0.2, 1.0)LongMemory.Forecasters.fi_forecast_plot — Method
fi_forecast_plot(x::AbstractArray, h::Int, d::Real)Plots the forecast of a long memory time series using the fractional differencing method.
Requires Plots.jl to be loaded, e.g. with using LongMemory, Plots.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.d::Real: The fractional differencing parameter.
Output
p1::Plot: The plot of the original time series and the forecast.
Notes
Multiple dispatch is used to plot the forecast of a time series with or without confidence bands. Plotting is done by calling the fi_forecast function.
Examples
julia> fi_forecast_plot(fi_gen(100,0.2), 10, 0.2)LongMemory.Forecasters.fi_ma_coefs — Method
fi_ma_coefs(d::Real, maxlags::Int)Computes the MA coefficients of the fractional differenced process with parameter d at lags 0, ..., maxlags-1.
Arguments
d::Real: The fractional differencing parameter.maxlags::Int: The number of lags to compute.
Output
ma_coefs::Array: The MA coefficients of the fractional differenced process with parameterdat lags 0, ...,maxlags-1, i.e. the coefficients of(1-L)^{-d}.
Notes
The MA coefficients are computed using the recursive formula ψ_j = ψ_{j-1} (j - 1 + d) / j for speed. The zero lag coefficient is included, it is 1. This matches the convention of csa_ma_coefs.
Examples
julia> fi_ma_coefs(0.2, 5)LongMemory.Forecasters.gregory_coeffs — Method
gregory_coeffs(N::Int)Computes the absolute values of the Gregory coefficients, |G_n| for n = 1, ..., N, used in the harmonic inverse transformation.
Arguments
N::Int: The number of coefficients to compute.
Output
coefs::Array: The Gregory coefficients.
Notes
The first coefficient is 1/2 and the rest are computed using the recursive formula. The zero lag coefficient is not computed, it is theoretically 1. The inverse of the harmonically weighted filter is 1 - Σ_{n≥1} |G_n| Lⁿ.
Examples
julia> gregory_coeffs(5)LongMemory.Forecasters.har_forecast — Method
har_forecast(x::AbstractArray, h::Int; flag::Bool = false, m::AbstractArray=[1,5,22])Computes the forecast of a time series by fitting and recursively forecasting the HAR model.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.
Output
xfor::Array: The forecast of the time series. The first T-max(m) elements are the original time series.
Optional Arguments
flag::Bool: If true, the output is a matrix where the first column is the forecast, the second column is the lower confidence band, and the third column is the upper confidence band. The default is false.m::Array: The lags to include in the HAR model. The default is [1,5,22].
Notes
The bands are the forecast ± 2 standard errors of the k-step forecast error, computed from the MA representation of the fitted HAR model (an AR(max(m)) model) and the residual standard deviation. Hence, they widen with the horizon. Parameter uncertainty is not taken into account.
Examples
julia> har_forecast(fi_gen(100,0.2), 10)LongMemory.Forecasters.har_forecast_plot — Method
har_forecast_plot(x::AbstractArray, h::Int; flag::Bool = true, m::AbstractArray=[1,5,22])Plots the forecast of a time series by fitting and recursively forecasting the HAR model.
Requires Plots.jl to be loaded, e.g. with using LongMemory, Plots.
Arguments
x::Array: The time series.h::Int: The number of periods to forecast.
Output
p1::Plot: The plot of the original time series and the forecast.
Optional Arguments
flag::Bool: If true, the output is a matrix where the first column is the forecast, the second column is the lower confidence band, and the third column is the upper confidence band. The default is true.m::Array: The lags to include in the HAR model. The default is [1,5,22].
Notes
Multiple dispatch is used to plot the forecast of a time series with or without confidence bands. Plotting is done by calling the har_forecast function.
Examples
julia> har_forecast_plot(fi_gen(100,0.2), 10)LongMemory.Forecasters.hitransform — Method
hitransform(x::AbstractArray)Computes the harmonic inverse transformation of a time series. For more details see Hassler and Hosseinkouchack (2020).
Arguments
x::Array: The time series.
Output
result::Array: The time series after the harmonic inverse transformation (new array, input not mutated).
Notes
The harmonic inverse transformation is computed using the FFT.
Examples
julia> hitransform(fi_gen(100,0.2))LongMemory.Forecasters.my_half_toeplitz — Method
my_half_toeplitz(coefs::AbstractArray)Constructs a bottom Toeplitz matrix from the given coefficients.
Arguments
coefs::Array: An array of coefficients.
Output
Toep::Array: The bottom Toeplitz matrix constructed from the given coefficients.
Examples
julia> my_half_toeplitz([1, 2, 3])Documentation for LongMemory.jl.