Long Memory Generation
Functions to generate time series long memory models. Methods include fractional differencing, error duration model, and à la cross-sectional aggregation.
LongMemory.GeneratingFunctions — Module
GeneratingFunctions
This module contains functions to generate time series with long memory.
Author
LongMemory.GeneratingFunctions.arfi_gen — Method
arfi_gen(T::Int, μ::Real, AR::AbstractArray, d::Real; σ=1)Generate a time series with long memory parameter d and length T using the ARFIMA(p,d,0) model.
Arguments
T::Int: length of the time seriesμ::Float64: mean of the time seriesAR::Array: AR coefficientsd::Float64: fractional difference parameter
Optional arguments
σ::Float64: standard deviation of the time series
Output
x::Vector: time series with long memory
Notes
The code is inspired by the function dgp_arfima.m by Carlos Vladimir Rodríguez Caballero (2023)
Examples
julia> arfi_gen(100, 0, [0.2; -0.5], 0.4)LongMemory.GeneratingFunctions.arfima_gen — Method
arfima_gen(T::Int, μ::Real, AR::AbstractArray, d::Real, MA::AbstractArray; σ=1)Generate a time series with long memory parameter d and length T using the ARFIMA(p,d,q) model.
Arguments
T::Int: length of the time seriesμ::Float64: mean of the time seriesAR::Array: AR coefficientsd::Float64: fractional difference parameterMA::Array: MA coefficients
Optional arguments
σ::Float64: standard deviation of the time series
Output
x::Vector: time series with long memory
Notes
The code is inspired by the function dgp_arfima.m by Carlos Vladimir Rodríguez Caballero (2023)
Examples
julia> arfima_gen(100, 0, [0.2; -0.5], 0.4, [-0.3; 0.1])LongMemory.GeneratingFunctions.csa_gen — Method
csa_gen(T::Int,p,q;μ=0,σ=1)Generate a time series with long memory parameter q and length T using the cross-sectional aggregated process. See Vera-Valdes(2021) for details.
Arguments
T::Int: length of the time seriesp::Float64: first parameter of the cross-sectional aggregated processq::Float64: second parameter of the cross-sectional aggregated process, which is related to the fractional difference parameterdbyq = 2(1-d)
Optional arguments
μ::Float64: mean of the time seriesσ::Float64: standard deviation of the time series
Output
x::Vector: time series with long memory
Examples
julia> csa_gen(100,1.2,1.4)LongMemory.GeneratingFunctions.csa_gen — Method
csa_gen(T::Int,N::Int,p,q;t=0.01;μ=0,σ=1)Generate a time series with long memory parameter q and length T using the cross-sectional aggregation of 'N' AR(1) processes à la Granger (1980).
Arguments
T::Int: length of the time seriesN::Int: number of AR(1) processesp::Float64: first parameter of the cross-sectional aggregated processq::Float64: second parameter of the cross-sectional aggregated process, which is related to the fractional difference parameterdbyq = 2(1-d)
Optional arguments
t::Float64: taper lengthμ::Float64: mean of the time seriesσ::Float64: standard deviation of the time series
Notes
Multiple dispatch is used to generate the finite sample process if 'N' is included in the arguments.
Output
x::Vector: time series with long memory
Examples
julia> csa_gen(100,100,1.2,1.4)LongMemory.GeneratingFunctions.csadiff — Method
csadiff(x,p,q)Generate long memory by using the moving average representation of the cross-sectional aggregated process using the fast Fourier algorithm. See Vera-Valdes(2021) for details.
Arguments
x::Vector: time seriesp::Float64: first parameter of the cross-sectional aggregated processq::Float64: second parameter of the cross-sectional aggregated process, which is related to the fractional difference parameterdbyq = 2(1-d)
Output
dx::Vector: time series with long memory
Notes
q determines the long memory parameter of the cross-sectional aggregated process. The relation q = 2(1-d) holds, where d is the fractional difference parameter. We use autoregressive formulas to efficiently compute the coefficients of the moving average representation of the cross-sectional aggregated process.
Examples
julia> csadiff(randn(100,1),1.2,1.4)LongMemory.GeneratingFunctions.davies_harte — Method
davies_harte(acv::AbstractArray)Generate a stationary Gaussian time series with autocovariances acv at lags 0, 1, ..., T-1 using the circulant embedding method of Davies and Harte (1987).
Arguments
acv::AbstractArray: autocovariances at lags 0, 1, ...,T-1
Output
x::Vector: time series of lengthT = length(acv)whose covariance matrix is exactly the Toeplitz matrix ofacv
Notes
The method embeds the covariance matrix in a circulant matrix of size 2(T-1) and uses the fast Fourier transform, so the cost is O(T log T). It is exact, in contrast to the truncated filters used in fi_gen or csa_gen, but it requires the circulant embedding to be nonnegative definite. This holds for the fractionally differenced process with d∈(-1/2,1/2); an error is thrown otherwise. See fi_exact_gen and csa_exact_gen for wrappers.
References
Davies, R. B., and Harte, D. S. (1987). Tests for Hurst effect. Biometrika, 74(1), 95-101.
Examples
julia> davies_harte(0.5 .^ (0:99))LongMemory.GeneratingFunctions.edm_gen — Method
edm_gen(T::Int,d; t=0.5, μ=0, σ=1)Generate a time series with long memory parameter d and length T using the error duration model à la Parke (1999).
Arguments
T::Int: length of the time seriesd::Float64: long memory parameter
Optional arguments
t::Float64: taper lengthμ::Float64: mean of the time seriesσ::Float64: standard deviation of the time series
Output
x::Vector: time series with long memory
Notes
The taper length t is the proportion of the time series that is pre-sampled to avoid the initial bias of the error duration model.
Examples
julia> edm_gen(100,0.4)LongMemory.GeneratingFunctions.fi_gen — Method
fi_gen(T,d;μ=0,σ=1)Generate a time series with long memory parameter d and length T using the fractional difference filter.
Arguments
T::Int: length of the time seriesd::Float64: fractional difference parameter
Optional arguments
μ::Float64: mean of the time seriesσ::Float64: standard deviation of the time series
Output
x::Vector: time series with long memory
Notes
Multiple dispatch is used for generation: If d is an integer, the function returns a time series with first or null difference. See fracdiff for details.
Examples
julia> fi_gen(100,0.4)LongMemory.GeneratingFunctions.fi_survival_probs — Method
fi_survival_probs(N::Int,d)Generate the survival probabilities of the error duration model à la Parke (1999).
Arguments
N::Int: length of the time seriesd::Float64: fractional difference parameter
Output
p::Vector: survival probabilities
Notes
The survival probabilities are computed using the recursive formula p_{t+1} = p_t * (t + d - 1) / (t + 1 - d) to avoid numerical overflow.
Examples
julia> fi_survival_probs(100,0.4)LongMemory.GeneratingFunctions.fracdiff — Method
fracdiff(x,d::Int)Compute the first or null difference of a time series x. Multiple dispatch is used to return the same input or call the function diff from the Julia standard library if d=0 or d=1, respectively. Any other integer d (e.g. d=-1, integration) falls back to the truncated filter used for fractional d.
Arguments
x::Vector: time seriesd::Int64: difference parameter
Output
dx::Vector: first or null difference ofx
Examples
julia> fracdiff(randn(100,1),1)LongMemory.GeneratingFunctions.fracdiff — Method
fracdiff(x,d)Compute the fractional difference of a time series x with fractional order d∈(-1/2,1/2).
Arguments
x::Vector: time seriesd::Float64: fractional difference parameter
Output
dx::Vector: fractional difference ofx
Notes
The function uses the fast Fourier transform to compute the convolution of the time series with the fractional difference filter. See Jensen and Nielsen (2014) for details. We use autoregressive formulas to efficiently compute the coefficients of the fractional difference filter.
Examples
julia> fracdiff(randn(100,1),0.4)LongMemory.GeneratingFunctions.hwfilter — Method
hwfilter(x::AbstractArray)Filter a time series x using the harmonically weighted filter.
Arguments
x::Vector: time series
Output
hwx::Vector: filtered time series
Notes
The harmonically weighted filter is computed using the fast Fourier transform.
Examples
julia> hwfilter(randn(100,1))LongMemory.GeneratingFunctions.hwp_gen — Method
hwp_gen(T;μ=0,σ=1)Generate a time series with long memory using the harmonically weighted process à la Hassler and Hosseinkouchack (2020).
Arguments
T::Int: length of the time seriesμ::Float64: mean of the time seriesσ::Float64: standard deviation of the time series
Output
x::Vector: time series with long memory
Examples
julia> hwp_gen(100)LongMemory.GeneratingFunctions.sds_gen — Method
sds_gen(T::Int,d; t=0.5, μ=0, σ=1)Generate a time series with long memory parameter d and length T using the stochastic duration shocks model.
Arguments
T::Int: length of the time seriesd::Float64: long memory parameter
Optional arguments
t::Float64: taper lengthμ::Float64: mean of the time seriesσ::Float64: standard deviation of the time series
Output
x::Vector: time series with long memory
Notes
The taper length t is the proportion of the time series that is pre-sampled to avoid the initial bias of the model. Reference: Parke (1999)
Examples
julia> sds_gen(100,0.4)Documentation for LongMemory.jl.