s-broda / ARCHModels.jl

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

Performance of `simulate` for DCC #92

Closed nilshg closed 3 years ago

nilshg commented 3 years ago

This might be a usage / "am I doing something wrong" question rather than an actual issue, but I'm trying to use ARCHModels in Monte Carlo pricing of some exotic derivatives, and am seeing quite a performance gap between simulating returns from a univariate compared to a multivariate model. An example:

using ARCHModels, MarketData, DataFrames
d = dropmissing(DataFrame(yahoo("^FTSE")))
rs = log.(d.AdjClose[end-251:end]) .- log.(d.AdjClose[end-252:end-1])
garch_model = fit(GARCH{1, 1}, rs)

@btime simulate(garch_model, 252)

gives 11.400 μs (8 allocations: 1.39 KiB) on my machine. By comparison:

d2 = dropmissing(DataFrame(yahoo("^SSMI")))
rs2 = log.(d2.AdjClose[end-251:end]) .- log.(d2.AdjClose[end-252:end-1])

d3 = dropmissing(DataFrame(yahoo("NQ=F")))
rs3 = log.(d2.AdjClose[end-251:end]) .- log.(d3.AdjClose[end-252:end-1])

dcc_model = fit(DCC, [rs rs2 rs3])

@btime simulate(dcc_model, 252)

gives 1.608 ms (22932 allocations: 5.13 MiB) so more than a 100-time slowdown. Is this expected or am I doing something wrong here?

s-broda commented 3 years ago

You're using it correctly. Some amount of slowdown is expected because of the matrix operations involved. Having said that, there was a rather egregious oversight in the code. Fixing this brought the runtime in your example down about 40% on my machine. I'll tag a new version once CI clears; look out for 1.4.2.

nilshg commented 3 years ago

Awesome, thank you so much - I didn't anticipate this running as fast as the simple univariate case of course, but great to see that the gap can be narrowed.

s-broda commented 3 years ago

FYI, the PR for the new version is here: https://github.com/JuliaRegistries/General/pull/41275. Once this gets merged, 1.4.2 should be available.