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

Benchmarks

Author
Affiliation

Aalborg University

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.

1 Loading packages

Loading the package and setting a seed for reproducibility.

using LongMemory, BenchmarkTools, Random, RCall
Random.seed!(1234)

2 Long memory generation

2.1 The fi_gen() function from the LongMemory.jl package

@benchmark fi_gen(10000, 0.2)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
 Range (min … max):  284.708 μs …   4.714 ms  ┊ GC (min … max): 0.00% … 90.08%
 Time  (median):     375.291 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   416.330 μs ± 140.155 μs  ┊ GC (mean ± σ):  9.13% ± 12.32%

            ▃█▃▁                                                 
  ▁▁▁▂▂▂▃▄▆▇█████▇▆▅▅▃▂▂▂▂▁▁▁▁▁▁▁▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁▂▁▁▁▁▁▁▁ ▂
  285 μs           Histogram: frequency by time          688 μs <

 Memory estimate: 2.81 MiB, allocs estimate: 65.

2.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.

R"library('fracdiff')"
@benchmark R"fracdiff::fracdiff.sim(10000, d = 0.2)"
BenchmarkTools.Trial: 85 samples with 1 evaluation per sample.
 Range (min … max):  58.646 ms …  60.814 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     58.980 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):   59.003 ms ± 238.710 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

                       ▂▂█▅▂▅▅▅▂▂ ▅   █▂   ▂                    
  ▅▁▅▁▁▁▅▅▅█▁▁▁▅▁█▅▅▁▅▅█████████████▅███▅▅▅█▅▅▅█▁▁▁▁▁▁▁▅▁█▁▁▁▅ ▁
  58.6 ms         Histogram: frequency by time         59.3 ms <

 Memory estimate: 1.53 KiB, allocs estimate: 69.

3 Fractional differencing

3.1 The fi_gen() function from the LongMemory.jl package

@benchmark fracdiff(randn(10000,1), 0.2)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
 Range (min … max):  268.500 μs …   5.455 ms  ┊ GC (min … max):  0.00% … 53.67%
 Time  (median):     365.041 μs               ┊ GC (median):     0.00%
 Time  (mean ± σ):   409.909 μs ± 188.899 μs  ┊ GC (mean ± σ):  10.79% ± 13.49%

    █▇                                                           
  ▁▃██▇▅██▇▇▄▃▂▂▂▂▂▃▃▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
  268 μs           Histogram: frequency by time         1.13 ms <

 Memory estimate: 2.81 MiB, allocs estimate: 65.

3.2 R: fracdiff::diffseries()

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

@benchmark R"fracdiff::diffseries(rnorm(10000), d = 0.2)"
BenchmarkTools.Trial: 5763 samples with 1 evaluation per sample.
 Range (min … max):  710.292 μs …  50.489 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     818.834 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   866.938 μs ± 725.883 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

        ▄█▇▃     ▃▅▃                                             
  ▂▃▃▄▄▇████▆▅▄▄▆████▆▄▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁▂▁▁▂▁▁▁▂▁▁▁▁▁▁▁▁▁▂▁▂ ▃
  710 μs           Histogram: frequency by time         1.34 ms <

 Memory estimate: 1.52 KiB, allocs estimate: 68.

3.3 R: LongMemoryTS:fdiff()

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

R"library('LongMemoryTS')"
@benchmark R"LongMemoryTS::fdiff(rnorm(10000), 0.2)"
BenchmarkTools.Trial: 1583 samples with 1 evaluation per sample.
 Range (min … max):  2.925 ms …  30.993 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     3.116 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):   3.158 ms ± 788.929 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

                        ▁▅▆▅█▄▄▅▅▁                             
  ▂▂▁▂▃▃▃▃▃▅▅▆█▆█▇█▇▇▆█▇███████████▇▇▆▅▅▄▃▃▃▃▃▃▂▂▁▂▂▂▂▂▃▁▁▂▂▂ ▄
  2.93 ms         Histogram: frequency by time        3.36 ms <

 Memory estimate: 1.52 KiB, allocs estimate: 68.

4 Long memory estimation

Data generation for all the estimators. The fi_gen() function is used to generate long memory data.

x = fi_gen(1000, 0.4);

4.1 The gph_est() function from the LongMemory.jl package

@benchmark gph_est(x; m = 0.5)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
 Range (min … max):  15.333 μs …  2.805 ms  ┊ GC (min … max): 0.00% … 78.49%
 Time  (median):     18.250 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   20.670 μs ± 48.916 μs  ┊ GC (mean ± σ):  5.80% ±  3.16%

           ▅█▇▅▂     ▁                                         
  ▂▅▅▇▆▄▅▄▇█████▆▆▆▇████▅▅▄▄▄▃▃▃▃▄▄▄▃▃▂▂▂▃▂▃▃▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁ ▃
  15.3 μs         Histogram: frequency by time        27.3 μs <

 Memory estimate: 97.47 KiB, allocs estimate: 62.

4.2 R LongMemoryTS: gph()

@benchmark R"LongMemoryTS::gph($x, m = floor(1000^0.5))"
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
 Range (min … max):  40.458 μs …  24.044 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     48.916 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   54.082 μs ± 250.357 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

                 ▁          ▁▅▅█▇▃▃                             
  ▁▁▂▂▃▃▃▃▃▄▄▆▆█▇███▇▇▇▇▆▇▇█████████▇▅▅▃▄▃▃▂▂▂▂▂▂▂▂▁▂▁▂▁▁▁▁▁▁▁ ▃
  40.5 μs         Histogram: frequency by time         59.2 μs <

 Memory estimate: 3.77 KiB, allocs estimate: 173.

4.3 R fracdiff: fdGPH()

@benchmark R"fracdiff::fdGPH($x)"
BenchmarkTools.Trial: 1348 samples with 1 evaluation per sample.
 Range (min … max):  2.533 ms … 22.510 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     3.075 ms              ┊ GC (median):    0.00%
 Time  (mean ± σ):   3.708 ms ±  1.999 ms  ┊ GC (mean ± σ):  0.00% ± 0.00%

   ▂▆█▆           ▁▁▁▁                                        
  ▆█████▇▁▄▁▁▁▁▁▁▇█████▇▆▅▆▆▅▄▄▆▄▆▄▄▆▄▁▁▄▁▁▄▁▆▅▄▄▄▄▅▁▅▅▄▆▄▄▆ █
  2.53 ms      Histogram: log(frequency) by time     11.3 ms <

 Memory estimate: 3.79 KiB, allocs estimate: 174.

5 Benchmarking in R using the microbenchmark package

We have use BenchmarkTools for benchmarking in Julia. We show that the RCall interface overhead is negligible.

R"library('microbenchmark')"
R"microbenchmark(fracdiff::fracdiff.sim(10000, d = 0.2), times = 33)"
┌ Warning: RCall.jl: Warning in microbenchmark(fracdiff::fracdiff.sim(10000, d = 0.2), times = 33) :
│   less accurate nanosecond times to avoid potential integer overflows
└ @ RCall ~/.julia/packages/RCall/WTNSB/src/io.jl:171
RObject{VecSxp}
Unit: milliseconds
                                   expr      min       lq     mean  median
 fracdiff::fracdiff.sim(10000, d = 0.2) 58.19097 58.54283 58.81303 58.8409
       uq      max neval
 59.00978 59.62897    33

Note that the times are similar so the overhead of RCall is negligible.

Citation

BibTeX citation:
@article{vera-valdés2025,
  author = {Vera-Valdés, J. Eduardo},
  title = {LongMemory.jl: {Generating,} {Estimating,} and {Forecasting}
    {Long} {Memory} {Models} in {Julia}},
  journal = {Journal of Open Source Software},
  volume = {10},
  number = {108},
  pages = {7708},
  date = {2025},
  url = {https://doi.org/10.21105/joss.07708},
  doi = {10.21105/joss.07708},
  langid = {en},
  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**.}
}
For attribution, please cite this work as:
Vera-Valdés, J. Eduardo. 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.