# ARFIMA estimation in Julia

**URL:** <https://discourse.julialang.org/t/arfima-estimation-in-julia/59041>\
**Category:** Statistics\
**Created:** [April 11, 2021, 5:00pm UTC](https://discourse.julialang.org/t/arfima-estimation-in-julia/59041 "2021-04-11T17:00:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [April 11, 2021, 5:00pm UTC](https://discourse.julialang.org/t/arfima-estimation-in-julia/59041/1 "2021-04-11T17:00:05Z")

</div>

Is there a package able to estimate an ARFIMA model in Julia (or just ARIMA for a start)?

I believe that the ARFIMA.jl package is just for simulating stochastic time-series that follow an ARFIMA process. Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [April 11, 2021, 5:07pm UTC](https://discourse.julialang.org/t/arfima-estimation-in-julia/59041/2 "2021-04-11T17:07:14Z")

</div>

@s-broda’s [ARCHModels](https://github.com/s-broda/ARCHModels.jl).jl can fit [ARMA{p,q}](https://s-broda.github.io/ARCHModels.jl/dev/univariatetypehierarchy/) models (but not yet ARIMA or ARFIMA).

```julia
julia> using ARCHModels;
julia> fit_arma(df, p, q) = fit(ARCH{0}, df, meanspec=ARMA{p,q});
julia> fit_arma(BG96, 2, 3)
TGARCH{0,0,0} model with Gaussian errors, T=1974.
Mean equation parameters:
────────────────────────────────────────────────
       Estimate Std.Error z value Pr(>|z|)
────────────────────────────────────────────────
c -0.00983746 0.0354041 -0.277862 0.7811
φ₁ 0.551574 0.589292 0.935995 0.3493
φ₂ -0.144346 1.92247 -0.0750838 0.9401
θ₁ -0.542057 0.591114 -0.91701 0.3591
θ₂ 0.113263 1.92454 0.0588521 0.9531
θ₃ 0.0501891 0.0282235 1.77828 0.0754
────────────────────────────────────────────────
Volatility parameters:
─────────────────────────────────────────
   Estimate Std.Error z value Pr(>|z|)
─────────────────────────────────────────
ω 0.220462 0.0117617 18.7441 <1e-77
─────────────────────────────────────────
julia>

```

Also self-tuning:

```julia
julia> auto_arma(df, bic) = selectmodel(ARCH{0}, df, meanspec=ARMA, criterion=bic, minlags=1, maxlags=3);
julia> auto_arma(BG96, bic) # ARMA(1,1)
TGARCH{0,0,0} model with Gaussian errors, T=1974.
Mean equation parameters:
─────────────────────────────────────────────
      Estimate Std.Error z value Pr(>|z|)
─────────────────────────────────────────────
c -0.0266446 0.0174716 -1.52502 0.1273
φ₁ -0.621838 0.160741 -3.86857 0.0001
θ₁ 0.643588 0.154303 4.17095 <1e-4
─────────────────────────────────────────────
Volatility parameters:
─────────────────────────────────────────
   Estimate Std.Error z value Pr(>|z|)
─────────────────────────────────────────
ω 0.220848 0.0118061 18.7063 <1e-77
─────────────────────────────────────────
julia> auto_arma(DOW29[:,1], bic) # ARMA(2,2)
TGARCH{0,0,0} model with Gaussian errors, T=2785.
Mean equation parameters:
───────────────────────────────────────────────
      Estimate Std.Error z value Pr(>|z|)
───────────────────────────────────────────────
c -0.166748 0.0681206 -2.44783 0.0144
φ₁ 0.0178542 0.0401341 0.444864 0.6564
φ₂ -0.932372 0.0803993 -11.5968 <1e-30
θ₁ -0.0191798 0.0463979 -0.413375 0.6793
θ₂ 0.903732 0.0963863 9.37614 <1e-20
───────────────────────────────────────────────
Volatility parameters:
─────────────────────────────────────────
   Estimate Std.Error z value Pr(>|z|)
─────────────────────────────────────────
ω 3.65185 0.220716 16.5455 <1e-60
─────────────────────────────────────────
julia> auto_arma(DOW29[:,3], bic) # ARMA(2,1)
TGARCH{0,0,0} model with Gaussian errors, T=2785.
Mean equation parameters:
────────────────────────────────────────────────
       Estimate Std.Error z value Pr(>|z|)
────────────────────────────────────────────────
c 0.00192406 0.0345892 0.0556262 0.9556
φ₁ -0.371152 0.2418 -1.53496 0.1248
φ₂ -0.145134 0.0625429 -2.32055 0.0203
θ₁ 0.231451 0.235409 0.983186 0.3255
────────────────────────────────────────────────
Volatility parameters:
─────────────────────────────────────────
   Estimate Std.Error z value Pr(>|z|)
─────────────────────────────────────────
ω 2.20732 0.164313 13.4336 <1e-40
─────────────────────────────────────────
julia> auto_arma(DOW29[:,9], bic) # ARMA(1,2)
TGARCH{0,0,0} model with Gaussian errors, T=2785.
Mean equation parameters:
──────────────────────────────────────────────
      Estimate Std.Error z value Pr(>|z|)
──────────────────────────────────────────────
c -0.0184696 0.0215819 -0.855789 0.3921
φ₁ 0.109868 0.306715 0.358211 0.7202
θ₁ -0.110765 0.308797 -0.358699 0.7198
θ₂ -0.107618 0.0347561 -3.09639 0.0020
──────────────────────────────────────────────
Volatility parameters:
─────────────────────────────────────────
   Estimate Std.Error z value Pr(>|z|)
─────────────────────────────────────────
ω 1.79002 0.109611 16.3307 <1e-59
─────────────────────────────────────────

```

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [April 11, 2021, 5:18pm UTC](https://discourse.julialang.org/t/arfima-estimation-in-julia/59041/3 "2021-04-11T17:18:18Z")

</div>

You can look at my [post](https://discourse.julialang.org/t/how-can-we-create-a-leaner-ecosystem-for-julia/32904) for an attempt to summarize the TS ecosystem in Julia:

- [ARCHModels](https://github.com/s-broda/ARCHModels.jl).jl can fit [ARMA{p,q}](https://s-broda.github.io/ARCHModels.jl/dev/univariatetypehierarchy/)
- [TSAnalysis](https://github.com/fipelle/TSAnalysis.jl) can fit ARIMA/VARIMA
- [StateSpaceModels](https://github.com/LAMPSPUC/StateSpaceModels.jl) fits seasonal ARIMA (sARIMA)

there are others…

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [April 11, 2021, 8:51pm UTC](https://discourse.julialang.org/t/arfima-estimation-in-julia/59041/4 "2021-04-11T20:51:48Z")

</div>

PS: while the Julia ecosystem has (multiple) options to estimate ARIMA/sARIMA/VARIMA, I don’t know any options to estimate an ARFIMA yet (only to simulate).  
Sometimes when I’m feeling [greedy](https://julialang.org/blog/2012/02/why-we-created-julia/) I code it up on my own & submit a PR 😉…

---

<div class="post-metadata">

**Author:** ![cgeoga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgeoga/32/216186_2.png) [@cgeoga](https://discourse.julialang.org/u/cgeoga)\
**Post date:** [April 11, 2021, 9:52pm UTC](https://discourse.julialang.org/t/arfima-estimation-in-julia/59041/5 "2021-04-11T21:52:16Z")

</div>

If you’re okay with writing a little code on your own and are treating the white noise forcing as Gaussian, then the spectral densities of (AR)(F)(I)(MA) processes are all pretty direct to work out and would only take a few lines of code to write. You could then write a Whittle-type likelihood approximation (or the [“debiased”](https://academic.oup.com/biomet/article/106/2/251/5318578) alteration) in just a few more lines of code, which you could then plop into any optimizer you wanted.

Alternatively, presumably it would be possible to use your spectral density and with a few more intermediate calculations plug in to @willtebbutt [TemporalGPs](https://github.com/JuliaGaussianProcesses/TemporalGPs.jl) package. I have never used it, though, and so maybe I’m wrong about that.
