Reputation: 817
I want to fit a student-t and a skewed student-t distribution to log returns.
For this purpose I use the stdFit
and sstdFit
function from the fGarch
package (would also use something else if someone knows a better option for both distributions).
My problem is, that the fit in most of the cases does not converge. Here some example code:
set.seed(123)
require(xts)
require(rugarch)
require(fGarch)
data(sp500ret)
spx = as.xts(sp500ret[1000:nrow(sp500ret),,drop=F])
hist(spx,200)
fit_std = stdFit(spx)
if(fit_std$convergence != 0){
print("stdFit did not converge")
}
fit_sstd = sstdFit(spx)
if(fit_sstd$code != 0){
print("sstdFit did not converge")
}
The only additional parameters I can pass to stdFit
and sstdFit
are parameters for the optimizer nlm
: https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/nlm
I would rather look for something like start value and / or boundaries.
Also I did not find an explanation to what the other options of fit_sstd$code
mean. I found code
having the values of [0,1,2,3]
at least.
Any ideas how I can improve the fitting? I need to repeat different fits automatically > 1 million times.
Thanks a lot!
Edit:
Here is my sessionInfo()
output to reproduce:
R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C
[5] LC_TIME=German_Germany.utf8
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] fGarch_4022.89 rugarch_1.4-9 xts_0.13.1 zoo_1.8-12
loaded via a namespace (and not attached):
[1] tidyselect_1.2.0 remotes_2.4.2 ks_1.14.0 reshape2_1.4.4
[5] lattice_0.20-45 colorspace_2.1-0 vctrs_0.6.2 generics_0.1.3
[9] SkewHyperbolic_0.4-0 utf8_1.2.3 rlang_1.1.0 pracma_2.4.2
[13] gbutils_0.5 pillar_1.9.0 glue_1.6.2 cvar_0.5
[17] lifecycle_1.0.3 plyr_1.8.8 stringr_1.5.0 timeDate_4022.108
[21] munsell_0.5.0 fBasics_4022.94 gtable_0.3.3 timeSeries_4021.105
[25] mvtnorm_1.1-3 fansi_1.0.4 Rcpp_1.0.10 KernSmooth_2.23-20
[29] scales_1.2.1 DistributionUtils_0.6-0 truncnorm_1.0-9 spd_2.0-1
[33] ggplot2_3.4.2 stringi_1.7.12 dplyr_1.1.1 rbibutils_2.2.13
[37] numDeriv_2016.8-1.1 cowplot_1.1.1 grid_4.2.3 Rdpack_2.4
[41] cli_3.6.1 tools_4.2.3 magrittr_2.0.3 Rsolnp_1.16
[45] tibble_3.2.1 pacman_0.5.1 spatial_7.3-16 pkgconfig_2.0.3
[49] GeneralizedHyperbolic_0.8-4 MASS_7.3-58.2 Matrix_1.5-3 rstudioapi_0.14
[53] R6_2.5.1 mclust_6.0.0 compiler_4.2.3
Upvotes: 1
Views: 89
Reputation: 263451
I eventually got the packages installed and my initial errors fixed. At that point I was getting the same results as you did. Looking at the code I wondered whether giving an entire xts object (rather than a "vector of quantiles" as described in the help page) could be the source of problems. So I tried:
fit_std = stdFit(spx[,1])
Warning messages:
1: In nlminb(start = start, objective = loglik, lower = c(-Inf, 0, :
NA/NaN function evaluation
2: In nlminb(start = start, objective = loglik, lower = c(-Inf, 0, :
NA/NaN function evaluation
3: In nlminb(start = start, objective = loglik, lower = c(-Inf, 0, :
NA/NaN function evaluation
> if(fit_std$convergence != 0){
+ print("stdFit did not converge")
+ }
So it converged. I then went back and ran it with stdFit(spx[,1])
. This time it converged, although the warning persisted. So was the initial lack of convergence due to your choice of the seed? I then tried recreating the lack of convergence to allow investigation. Again it converged. So did running a successful fit change the starting values?
Opinion: Your effort to fit multiple series should proceed by passing atomic vectors extracted from the xts objects and you should continue with the checks for convergence.
Upvotes: 0