Skip to content

Commit

Permalink
add convenience functions for ARMA and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
s-broda committed May 13, 2022
1 parent 6333b59 commit 99b389f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ARCHModels"
uuid = "6d3278bc-c23a-5105-85e5-0d57d2bf684f"
authors = ["Simon Broda <simon.broda@alumni.ethz.ch> and contributors."]
version = "2.1"
version = "2.2"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Volatility parameters:
ω 0.220848 0.0118061 18.7063 <1e-77
─────────────────────────────────────────
```
In this case, an ARMA(1, 1) specification was selected.
In this case, an ARMA(1, 1) specification was selected. As a convenience, the above can equivalently achieved using `selectmodel(ARMA, BG96)`.

As a final example, a construction like the following can be used to automatically select not just the lag length, but also the class of GARCH model and the error distribution:

Expand Down
24 changes: 23 additions & 1 deletion src/meanspecs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ end
ARMA{p, q, T} <: MeanSpec{T}
An ARMA(p, q) mean specification.
"""

struct ARMA{p, q, T} <: MeanSpec{T}
coefs::Vector{T}
function ARMA{p, q, T}(coefs::Vector) where {p, q, T}
Expand All @@ -110,6 +109,29 @@ struct ARMA{p, q, T} <: MeanSpec{T}
end
end

"""
fit(t::Type{<:ARMA}, data; kwargs...) -> UnivariateARCHModel
Fit an `ARMA{p, q}` model to `data`.
"""
fit(t::Type{<:ARMA}, data; kwargs...) = fit(ARCH{0}, data; meanspec=t, kwargs...)

"""
selectmodel(::Type{<:ARMA}, data; kwargs...) -> UnivariateARCHModel
Fit a number of `ARMA{p, q}` models to `data` and return that which
minimizes the [BIC](https://en.wikipedia.org/wiki/Bayesian_information_criterion).
# Keyword arguments:
- `dist=StdNormal`: the error distribution.
- `minlags=1`: minimum lag length to try in each parameter of `VS`.
- `maxlags=3`: maximum lag length to try in each parameter of `VS`.
- `criterion=bic`: function that takes a `UnivariateARCHModel` and returns the criterion to minimize.
- `show_trace=false`: print `criterion` to screen for each estimated model.
- `algorithm=BFGS(), autodiff=:forward, kwargs...`: passed on to the optimizer.
"""
selectmodel(t::Type{<:ARMA}, data; kwargs...) = selectmodel(ARCH{0}, data; meanspec=t, kwargs...)

"""
ARMA{p, q}(coefs::Vector)
Create an ARMA(p, q) model.
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ end
@test all(isapprox(coef(am), coef(fit(GARCH{1, 1}, BG96, meanspec=Intercept)), rtol=1e-4))
@test coefnames(am)[end] == "X"
@test all(isapprox(coef(am), coef(fit(GARCH{1, 1}, model.model)), rtol=1e-4))
@test sum(coef(fit(ARMA{1, 1}, BG96))) 0.21595383060382695
@test sum(coef(selectmodel(ARMA, BG96; minlags=2, maxlags=3))) 0.25404112526031397
end

@testset "VaR" begin
Expand Down

2 comments on commit 99b389f

@s-broda
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/60206

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.2.0 -m "<description of version>" 99b389f677edb1f43f2bfc31176ff2c635ea36dc
git push origin v2.2.0

Please sign in to comment.