LongMemory.jl: Generating, Estimating, and Forecasting Long Memory Models in Julia

Benchmarks

Abstract

LongMemory.jl is a package for time series long memory modelling in Julia. The package provides functions for generating long memory, estimating the parameters of the models, and simulation. Generating methods include fractional differencing, stochastic error duration, and cross-sectional aggregation. Estimators include those inspired by the log-periodogram regression and parametric ones. This notebook provides benchmarks for the LongMemory.jl package including against current alternatives. The package is closely related to the R packages LongMemoryTS and fracdiff.

Citation

If you use this package in your research, please cite it as:

Vera-Valdés, J. E., (2025). “LongMemory.jl: Generating, Estimating, and Forecasting Long Memory Models in Julia”. Journal of Open Source Software, 10(108), 7708, https://doi.org/10.21105/joss.07708

@article{Vera-Valdés2025, 
author = {J. Eduardo Vera-Valdés}, 
title = {LongMemory.jl: Generating, Estimating, and Forecasting Long Memory Models in Julia}, 
journal = {Journal of Open Source Software},
doi = {10.21105/joss.07708}, 
url = {https://doi.org/10.21105/joss.07708}, 
year = {2025}, 
publisher = {The Open Journal}, 
volume = {10}, 
number = {108}, 
pages = {7708}
 }

Loading packages

Loading the package and setting a seed

{julia, cache = TRUE} using LongMemory, BenchmarkTools, Random, RCall Random.seed!(1234)

Long memory generation

The fi_gen() function, which uses the cumulative method.

{julia, cache = TRUE} @benchmark fi_gen(10000, 0.2)

R: benchmarking the fracdiff.sim() function.

Loading the R packages. The R package fracdiff is used for fractional differencing generation using fracdiff::fracdiff.sim(). Benchmarking the fractional differencing generation by the R package fracdiff using RCall.

{julia, cache = TRUE} R"library(fracdiff)" @benchmark R"fracdiff::fracdiff.sim(10000, d = 0.2)"

For comparison purposes, the following benchmark is done in R using the microbenchmark package.

{julia, cache = TRUE} R"library(microbenchmark)" R"microbenchmark(fracdiff::fracdiff.sim(10000, d = 0.2), times = 33)"

Note that the times are similar. Hence, for ease of use, the next benchmarks are done using BenchmarkTools.

Fractional differencing

The fi_gen() function

{julia, cache = TRUE} @benchmark fracdiff(randn(10000,1), 0.2)

R: fracdiff::diffseries()

The R package fracdiff is used for fractional differencing using fracdiff::diffseries().

{julia, cache = TRUE} @benchmark R"fracdiff::diffseries(rnorm(10000), d = 0.2)"

R: LongMemoryTS:fdiff()

Loading the R package LongMemoryTS. The LongMemoryTS::fdiff() function is used for fractional differencing.

{julia, cache = TRUE} R"library(LongMemoryTS)" @benchmark R"LongMemoryTS::fdiff(rnorm(10000), 0.2)"

Comparing accuracy

```{julia, cache = TRUE} t = 20 x = randn(t,1) d = 0.2

fd_LongMemoryjl = fracdiff(x, d) fd_fracdiff = R”fracdiff::diffseries($x, d = \(d)"[1:t] fd_LongMemoryTS = R"LongMemoryTS::fdiff(\)x, d = $d)“[1:t]

[fd_LongMemoryjl fd_fracdiff fd_LongMemoryTS]








# Long memory estimation

Data generation.







```{julia, cache = TRUE}
x = fi_gen(1000, 0.4);

The gph_est() function

{julia, cache = TRUE} @benchmark gph_est(x; m = 0.5)

LongMemoryTS: gph()

{julia, cache = TRUE} @benchmark R"LongMemoryTS::gph($x, m = floor(1000^0.5))"

fracdiff: fdGPH()

{julia, cache = TRUE} @benchmark R"fracdiff::fdGPH($x)"

Comparing accuracy

```{julia, cache = TRUE} gph_LongMemoryjl = gph_est(x; m = 0.5) gph_LongMemoryTS = R”LongMemoryTS::gph(X = \(x, m = floor(1000^0.5))"[1] gph_fracdiff = R"fracdiff::fdGPH(\)x)$d”[1]

[gph_LongMemoryjl gph_LongMemoryTS gph_fracdiff] ```