s-broda / ARCHModels.jl

A Julia package for estimating ARMA-GARCH models.
https://juliaeconometrics.wordpress.com/
Other
90 stars 18 forks source link

Empty volatilities, bounds errors #102

Closed ancapdev closed 2 years ago

ancapdev commented 2 years ago

On version 2.2.0.

The following throws when trying to display the model (in a notebook)

X = [-49.78749999996362, 2951.7375000000347, 1496.437499999923, 973.8375, 2440.662500000128, 2578.062500000019, 1064.42500000032, 3378.0625000002415, -1971.5000000001048, 4373.899999999894]
am = fit(GARCH{2, 2}, X; meanspec = ARMA{2, 2})

Outputs:

LAPACKException(1)

Stacktrace:
  [1] chklapackerror(ret::Int64)
    @ LinearAlgebra.LAPACK ~/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/lapack.jl:43
  [2] trtrs!(uplo::Char, trans::Char, diag::Char, A::Matrix{Float64}, B::Matrix{Float64})
    @ LinearAlgebra.LAPACK ~/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/lapack.jl:3431
  [3] ldiv!
    @ ~/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/triangular.jl:727 [inlined]
  [4] inv(A::UpperTriangular{Float64, Matrix{Float64}})
    @ LinearAlgebra ~/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/triangular.jl:809
  [5] inv(A::Matrix{Float64})
    @ LinearAlgebra ~/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/dense.jl:872
  [6] vcov(am::UnivariateARCHModel{Float64, GARCH{2, 2, Float64}, StdNormal{Float64}, ARMA{2, 2, Float64}})
    @ ARCHModels ~/.julia/packages/ARCHModels/2J17E/src/general.jl:45
  [7] stderror(am::UnivariateARCHModel{Float64, GARCH{2, 2, Float64}, StdNormal{Float64}, ARMA{2, 2, Float64}})
    @ ARCHModels ~/.julia/packages/ARCHModels/2J17E/src/general.jl:63
  [8] show(io::IOContext{IOBuffer}, am::UnivariateARCHModel{Float64, GARCH{2, 2, Float64}, StdNormal{Float64}, ARMA{2, 2, Float64}})
    @ ARCHModels ~/.julia/packages/ARCHModels/2J17E/src/univariatearchmodel.jl:586
[...]

Digging a little deeper, volatilities(am) returns an empty vector.

Tracking further, from volatilities():

T = Float64
VS = GARCH{2, 2, Float64}
SD = StdNormal{Float64}
ht = Vector{T}(undef, 0)
lht = Vector{T}(undef, 0)
zt = Vector{T}(undef, 0)
at = Vector{T}(undef, 0)
loglik!(ht, lht, zt, at, VS, SD, am.meanspec, am.data, vcat(am.spec.coefs, am.dist.coefs, am.meanspec.coefs))

Returns -Inf and doesn't fill the ht vector.

Not sure where to go from there. Random changes to the input make it work or not work and seems quite brittle.

s-broda commented 2 years ago

Thank you. This will be fixed in 2.2.1, see #103

I still wouldn't put much trust in the estimation results in this particular case, because you're estimating 10 parameters from 8 data points (after losing 2 observations due to the lags), meaning the parameters are not identified (though I assume that in your real use case, the data set is larger).

ancapdev commented 2 years ago

The real data is much longer and it's sliding over a time series. I expect to have very low confidence at the start of the process. I had initially set my minimum window to 10 samples arbitrarily for testing and came upon this.

Thanks for the quick fix!