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
— ModuleGeneratingFunctions
This module contains functions to generate time series with long memory.
Author
LongMemory.GeneratingFunctions.arfi_gen
— Methodarfi_gen(T::Int, μ::Real, AR::Array, 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
— Methodarfima_gen(T::Int, μ::Real, AR::Array, d::Real, MA::Array; σ=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
— Methodcsa_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 parameterd
byq = 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
— Methodcsa_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 parameterd
byq = 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
— Methodcsadiff(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 parameterd
byq = 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.edm_gen
— Methodedm_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
— Methodfi(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(100,0.4)
LongMemory.GeneratingFunctions.fi_gen
— Methodfi_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" fisurvivalprobs(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
— Methodfracdiff(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.fracdiff
— Methodfracdiff(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=1
or d=0
, respectively.
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.hwfilter
— Methodhwfilter(x::Array)
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
— Methodhwp_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
— Methodsds_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.