As assessed by the title, I'm trying to estimate a GARCH(p,q) model to forecast stock market volatility and, in order to be able to do that, I've to identify the optimal number of lags, p and q, to fit the model properly. Can someone of you suggest me the proper function/procedure to do that in Matlab? I looked for that in Mathworks and in the Internet, but I found nothing whatsoever. Thanks for helping.
work you way from GARCH(4,4) to GARCH(0,0) removing the intercept too. 5*5*2-1 = 49 estimations
Lastly your real test should be an out-of-sample study of the forecast error distribution, and really look at whether your GARCH adds value.
It's ok to have a biased estimation of the conditional variance if the forecast error variance is smaller than a non-biased estimation. But again, that depends on the use you have for your forecast.
If you have the optimization toolkit, you can download a free software package written by Kevin Sheppard of the Mann Quantitative Finance Institute at the Uni of Oxford. He has all the tools you'll need. Link below.
Generally, there's no agreed upon methodology to do what you want to do. You should start by plotting the auto-correlations of your time series and the partial auto-correlations and taking a look to see where the bulk of concentration is. This should give you a starting point. Since GARCH/ARCH/etc. are auto-regressive, the number of lags is not super important.
Then test up from 1/1 to whatever you deem necessary. Compare BICs. I wouldn't go with AIC simply because it doesn't punish noise from added lags enough.