|
Dear All,
first of all thanks for the great package! I'm trying to get volatility forecasts. So I tried a couple of packages and I really like the roll functionality provided within the rugarch package but am finding inconsistencies with the results from two garch packages: 1) I run GA3=garchFit(formula=~arma(1,0)+aparch(1,1),data=SPX.log.ret,cond.dist="sstd") modeltofit=ugarchspec(variance.model = list(model = "apARCH", garchOrder = c(1, 1), submodel = NULL, external.regressors = NULL, variance.targeting = FALSE), mean.model = list(armaOrder = c(1, 0), include.mean = TRUE, archm = FALSE, archpow = 1, arfima = FALSE, external.regressors = NULL, archex = FALSE), distribution.model = "sstd", start.pars = list(), fixed.pars = list()) GAA3=ugarchfit(spec=modeltofit,data=SPX.log.ret) As you can see from the results below the parameter coefficients are different but similar but the significance is much lower for rugarch. Do you know why? 2) I then run volforecast=ugarchroll(spec=modeltofit, data = last(SPX.log.ret,550), n.ahead = 42, forecast.length = 100, refit.every = 25) sigma=as.data.frame(volforecast) sigmat <- as.POSIXct(strptime(sigma[,1],format="%Y-%m-%d")) sigma2 <- xts(sigma[,3],order.by=sigmat)*100*sqrt(252) And the results seems to me too low to represent the expected vol in 21 days. Could you please point me in the right direction? Thank you! ********************** RESULTS ********************** fGarch---------------------- > summary(GA3) Title: GARCH Modelling Call: garchFit(formula = ~arma(1, 0) + aparch(1, 1), data = SPX.log.ret, cond.dist = "sstd") Mean and Variance Equation: data ~ arma(1, 0) + aparch(1, 1) <environment: 0x000000000c09f038> [data = SPX.log.ret] Conditional Distribution: sstd Coefficient(s): mu ar1 omega alpha1 gamma1 beta1 0.00025599 -0.06942414 0.00011829 0.08504516 0.99999999 0.91557956 delta skew shape 1.11700143 0.86337982 5.35586013 Std. Errors: based on Hessian Error Analysis: Estimate Std. Error t value Pr(>|t|) mu 2.560e-04 2.023e-04 1.266 0.205659 ar1 -6.942e-02 2.332e-02 -2.977 0.002907 ** omega 1.183e-04 3.481e-05 3.399 0.000677 *** alpha1 8.505e-02 1.285e-02 6.616 3.69e-11 *** gamma1 1.000e+00 1.441e-02 69.414 < 2e-16 *** beta1 9.156e-01 1.006e-02 91.041 < 2e-16 *** delta 1.117e+00 1.962e-01 5.693 1.25e-08 *** skew 8.634e-01 2.755e-02 31.337 < 2e-16 *** shape 5.356e+00 8.347e-01 6.416 1.40e-10 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Log Likelihood: 5271.315 normalized: 3.1433 Description: Tue Jun 12 09:02:05 2012 by user: cora Standardised Residuals Tests: Statistic p-Value Jarque-Bera Test R Chi^2 2459.58 0 Shapiro-Wilk Test R W 0.9528365 0 Ljung-Box Test R Q(10) 11.72432 0.3039307 Ljung-Box Test R Q(15) 15.45374 0.4192542 Ljung-Box Test R Q(20) 21.50983 0.3676896 Ljung-Box Test R^2 Q(10) 90.12559 5.107026e-15 Ljung-Box Test R^2 Q(15) 91.15075 6.047385e-13 Ljung-Box Test R^2 Q(20) 91.74618 3.664247e-11 LM Arch Test R TR^2 26.18211 0.01011463 Information Criterion Statistics: AIC BIC SIC HQIC -6.275867 -6.246754 -6.275924 -6.265082 ******************************+ ****************************** rugarch-------------------- > show(GAA3) *---------------------------------* * GARCH Model Fit * *---------------------------------* Conditional Variance Dynamics ----------------------------------- GARCH Model : apARCH(1,1) Mean Model : ARFIMA(1,0,0) Distribution : sstd Optimal Parameters ------------------------------------ Estimate Std. Error t value Pr(>|t|) mu 0.000237 0.000190 1.2474e+00 0.212265 ar1 -0.069601 0.024100 -2.8881e+00 0.003876 omega 0.000175 0.000148 1.1823e+00 0.237092 alpha1 0.084114 0.011113 7.5687e+00 0.000000 beta1 0.920963 0.009835 9.3640e+01 0.000000 gamma1 1.000000 0.000000 2.6926e+06 0.000000 delta 1.025983 0.159330 6.4393e+00 0.000000 skew 0.860581 0.027580 3.1203e+01 0.000000 shape 5.561683 0.875725 6.3509e+00 0.000000 Robust Standard Errors: Estimate Std. Error t value Pr(>|t|) mu 0.000237 NaN NaN NaN ar1 -0.069601 NaN NaN NaN omega 0.000175 NaN NaN NaN alpha1 0.084114 NaN NaN NaN beta1 0.920963 NaN NaN NaN gamma1 1.000000 NaN NaN NaN delta 1.025983 NaN NaN NaN skew 0.860581 NaN NaN NaN shape 5.561683 NaN NaN NaN LogLikelihood : 5291.85 Information Criteria ------------------------------------ Akaike -6.3004 Bayes -6.2712 Shibata -6.3004 Hannan-Quinn -6.2896 Q-Statistics on Standardized Residuals ------------------------------------ statistic p-value Lag10 8.594 0.4756 Lag15 13.965 0.4523 Lag20 20.967 0.3386 H0 : No serial correlation Q-Statistics on Standardized Squared Residuals ------------------------------------ statistic p-value Lag10 28.13 0.0009072 Lag15 31.84 0.0042245 Lag20 35.40 0.0124798 ARCH LM Tests ------------------------------------ Statistic DoF P-Value ARCH Lag[2] 12.84 2 0.001630 ARCH Lag[5] 14.26 5 0.014050 ARCH Lag[10] 28.19 10 0.001683 Nyblom stability test ------------------------------------ Joint Statistic: NA Individual Statistics: mu 0.90793 ar1 0.11145 omega 0.91076 alpha1 0.53714 beta1 0.60241 gamma1 NA delta 0.84958 skew 0.06079 shape 0.50963 Asymptotic Critical Values (10% 5% 1%) Joint Statistic: 2.1 2.32 2.82 Individual Statistic: 0.35 0.47 0.75 Sign Bias Test ------------------------------------ t-value prob sig Sign Bias 0.7081 0.478964 Negative Sign Bias 2.7958 0.005236 *** Positive Sign Bias 2.7352 0.006301 *** Joint Effect 15.8663 0.001208 *** Adjusted Pearson Goodness-of-Fit Test: ------------------------------------ group statistic p-value(g-1) 1 20 53.65 3.733e-05 2 30 62.55 2.942e-04 3 40 67.52 3.081e-03 4 50 86.60 7.431e-04 Elapsed time : 4.712 |
|
1. Please examples with reproducible data for such a detailed question.
SPX.log.ret is not a commom data object found in any of the packages I know of. 2. How is the significance much lower? Looking at the Pr(>|t|) column they both look very significant across all parameters. The fact that the robust s.e. have NaN means that the robust hessian could not be calculated indicating that you need to tune the solver/use scaling (set 'fit.control=list(scale=1)'). Looking at the results, this is likely because of the 'gamma' parameter hitting its upper limit. 3. This is a rolling out of sample forecast which means that you are getting rolling estimates using 100 out of sample data points from the end of your dataset. As to the "expected" vol in 21 days ROLLING 1 day at a time, 'n.ahead=21', you need to pass this argument to the as.data.frame method or better still use: 'sigma=as.data.frame(volforecast, which = "sigma")'. This will be reverting to its long run mean. I really don't know what you expect as being reasonable or not. -Alexios On 12/06/2012 08:49, Belgarath wrote: > Dear All, > > first of all thanks for the great package! > > I'm trying to get volatility forecasts. So I tried a couple of packages and > I really like the roll functionality provided within the rugarch package but > am finding inconsistencies with the results from two garch packages: > > 1) > I run > > GA3=garchFit(formula=~arma(1,0)+aparch(1,1),data=SPX.log.ret,cond.dist="sstd") > > modeltofit=ugarchspec(variance.model = list(model = "apARCH", garchOrder = > c(1, 1), > submodel = NULL, external.regressors = NULL, variance.targeting = FALSE), > mean.model = list(armaOrder = c(1, 0), include.mean = TRUE, archm = FALSE, > archpow = 1, arfima = FALSE, external.regressors = NULL, archex = FALSE), > distribution.model = "sstd", start.pars = list(), fixed.pars = list()) > GAA3=ugarchfit(spec=modeltofit,data=SPX.log.ret) > > As you can see from the results below the parameter coefficients are > different but similar but the significance is much lower for rugarch. Do you > know why? > > 2) > I then run > > volforecast=ugarchroll(spec=modeltofit, data = last(SPX.log.ret,550), > n.ahead = 42, > forecast.length = 100, refit.every = 25) > sigma=as.data.frame(volforecast) > sigmat<- as.POSIXct(strptime(sigma[,1],format="%Y-%m-%d")) > sigma2<- xts(sigma[,3],order.by=sigmat)*100*sqrt(252) > > And the results seems to me too low to represent the expected vol in 21 > days. Could you please point me in the right direction? > > Thank you! > > > > ********************** > RESULTS > ********************** > > > fGarch---------------------- >> summary(GA3) > > Title: > GARCH Modelling > > Call: > garchFit(formula = ~arma(1, 0) + aparch(1, 1), data = SPX.log.ret, > cond.dist = "sstd") > > Mean and Variance Equation: > data ~ arma(1, 0) + aparch(1, 1) > <environment: 0x000000000c09f038> > [data = SPX.log.ret] > > Conditional Distribution: > sstd > > Coefficient(s): > mu ar1 omega alpha1 gamma1 beta1 > 0.00025599 -0.06942414 0.00011829 0.08504516 0.99999999 0.91557956 > delta skew shape > 1.11700143 0.86337982 5.35586013 > > Std. Errors: > based on Hessian > > Error Analysis: > Estimate Std. Error t value Pr(>|t|) > mu 2.560e-04 2.023e-04 1.266 0.205659 > ar1 -6.942e-02 2.332e-02 -2.977 0.002907 ** > omega 1.183e-04 3.481e-05 3.399 0.000677 *** > alpha1 8.505e-02 1.285e-02 6.616 3.69e-11 *** > gamma1 1.000e+00 1.441e-02 69.414< 2e-16 *** > beta1 9.156e-01 1.006e-02 91.041< 2e-16 *** > delta 1.117e+00 1.962e-01 5.693 1.25e-08 *** > skew 8.634e-01 2.755e-02 31.337< 2e-16 *** > shape 5.356e+00 8.347e-01 6.416 1.40e-10 *** > --- > Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > > Log Likelihood: > 5271.315 normalized: 3.1433 > > Description: > Tue Jun 12 09:02:05 2012 by user: cora > > > Standardised Residuals Tests: > Statistic p-Value > Jarque-Bera Test R Chi^2 2459.58 0 > Shapiro-Wilk Test R W 0.9528365 0 > Ljung-Box Test R Q(10) 11.72432 0.3039307 > Ljung-Box Test R Q(15) 15.45374 0.4192542 > Ljung-Box Test R Q(20) 21.50983 0.3676896 > Ljung-Box Test R^2 Q(10) 90.12559 5.107026e-15 > Ljung-Box Test R^2 Q(15) 91.15075 6.047385e-13 > Ljung-Box Test R^2 Q(20) 91.74618 3.664247e-11 > LM Arch Test R TR^2 26.18211 0.01011463 > > Information Criterion Statistics: > AIC BIC SIC HQIC > -6.275867 -6.246754 -6.275924 -6.265082 > > ******************************+ > ****************************** > > > rugarch-------------------- >> show(GAA3) > > *---------------------------------* > * GARCH Model Fit * > *---------------------------------* > > Conditional Variance Dynamics > ----------------------------------- > GARCH Model : apARCH(1,1) > Mean Model : ARFIMA(1,0,0) > Distribution : sstd > > Optimal Parameters > ------------------------------------ > Estimate Std. Error t value Pr(>|t|) > mu 0.000237 0.000190 1.2474e+00 0.212265 > ar1 -0.069601 0.024100 -2.8881e+00 0.003876 > omega 0.000175 0.000148 1.1823e+00 0.237092 > alpha1 0.084114 0.011113 7.5687e+00 0.000000 > beta1 0.920963 0.009835 9.3640e+01 0.000000 > gamma1 1.000000 0.000000 2.6926e+06 0.000000 > delta 1.025983 0.159330 6.4393e+00 0.000000 > skew 0.860581 0.027580 3.1203e+01 0.000000 > shape 5.561683 0.875725 6.3509e+00 0.000000 > > Robust Standard Errors: > Estimate Std. Error t value Pr(>|t|) > mu 0.000237 NaN NaN NaN > ar1 -0.069601 NaN NaN NaN > omega 0.000175 NaN NaN NaN > alpha1 0.084114 NaN NaN NaN > beta1 0.920963 NaN NaN NaN > gamma1 1.000000 NaN NaN NaN > delta 1.025983 NaN NaN NaN > skew 0.860581 NaN NaN NaN > shape 5.561683 NaN NaN NaN > > LogLikelihood : 5291.85 > > Information Criteria > ------------------------------------ > > Akaike -6.3004 > Bayes -6.2712 > Shibata -6.3004 > Hannan-Quinn -6.2896 > > Q-Statistics on Standardized Residuals > ------------------------------------ > statistic p-value > Lag10 8.594 0.4756 > Lag15 13.965 0.4523 > Lag20 20.967 0.3386 > > H0 : No serial correlation > > Q-Statistics on Standardized Squared Residuals > ------------------------------------ > statistic p-value > Lag10 28.13 0.0009072 > Lag15 31.84 0.0042245 > Lag20 35.40 0.0124798 > > ARCH LM Tests > ------------------------------------ > Statistic DoF P-Value > ARCH Lag[2] 12.84 2 0.001630 > ARCH Lag[5] 14.26 5 0.014050 > ARCH Lag[10] 28.19 10 0.001683 > > Nyblom stability test > ------------------------------------ > Joint Statistic: NA > Individual Statistics: > mu 0.90793 > ar1 0.11145 > omega 0.91076 > alpha1 0.53714 > beta1 0.60241 > gamma1 NA > delta 0.84958 > skew 0.06079 > shape 0.50963 > > Asymptotic Critical Values (10% 5% 1%) > Joint Statistic: 2.1 2.32 2.82 > Individual Statistic: 0.35 0.47 0.75 > > Sign Bias Test > ------------------------------------ > t-value prob sig > Sign Bias 0.7081 0.478964 > Negative Sign Bias 2.7958 0.005236 *** > Positive Sign Bias 2.7352 0.006301 *** > Joint Effect 15.8663 0.001208 *** > > > Adjusted Pearson Goodness-of-Fit Test: > ------------------------------------ > group statistic p-value(g-1) > 1 20 53.65 3.733e-05 > 2 30 62.55 2.942e-04 > 3 40 67.52 3.081e-03 > 4 50 86.60 7.431e-04 > > > Elapsed time : 4.712 > > -- > View this message in context: http://r.789695.n4.nabble.com/rugarch-and-fGarch-tp4633077.html > Sent from the Rmetrics mailing list archive at Nabble.com. > > _______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions should go. _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. |
|
Hello Alexios,
thank you for the quick reply! Apologies but yesterday yahoo finance was not working so could not follow up with an appropriate reproducible example: 1) ---- getSymbols("^GSPC", src="yahoo") SPY.log.ret=ClCl(GSPC) GA3=garchFit(formula=~arma(1,0)+aparch(1,1),data=last(SPY.log.ret,1371),cond.dist="sstd") summary(GA3) modeltofit=ugarchspec(variance.model = list(model = "apARCH", garchOrder = c(1, 1), submodel = NULL, external.regressors = NULL, variance.targeting = FALSE), mean.model = list(armaOrder = c(1, 0), include.mean = TRUE, archm = FALSE, archpow = 1, arfima = FALSE, external.regressors = NULL, archex = FALSE), distribution.model = "sstd", start.pars = list(), fixed.pars = list()) GAA3=ugarchfit(spec=modeltofit,data=last(SPY.log.ret,1371)) show(GAA3) volforecast=ugarchroll(spec=modeltofit,data=last(SPY.log.ret,1371), n.ahead = 21, forecast.length = 420, refit.every = 21) sigma=as.data.frame(volforecast,which="density",n.ahead=21) sigmat <- as.POSIXct(strptime(sigma[,1],format="%Y-%m-%d")) sigma2 <- xts(sigma[,3],order.by=sigmat)*100*sqrt(252) plot(sigma2) --- Detailed results are below, but to reply to your points: 2) rugarch omega is 0.000618 t:1.5062e+00 p:0.132023 while fGarch omega is 3.922e-04 t:3.970 p:7.19e-05 which is more significant. 3) Is the code above usage correct to extract the forecasts? I tried to use the sigma=as.data.frame(volforecast, which = "sigma") but it only return the first 21 forecasts. How do I extract the long term mean of the st dev? 4) I have one more question: the dates in the sigma=as.data.frame(volforecast,which="density",n.ahead=21) are alligned with the date the forecast refers to no the date the forcast is made (ie. it will be delayed by 21 days in a chart) correct? Thank you again for the help and the package! Marco ***************** > show(GAA3) *---------------------------------* * GARCH Model Fit * *---------------------------------* Conditional Variance Dynamics ----------------------------------- GARCH Model : apARCH(1,1) Mean Model : ARFIMA(1,0,0) Distribution : sstd Optimal Parameters ------------------------------------ Estimate Std. Error t value Pr(>|t|) mu 0.000197 0.000007 2.7154e+01 0.000000 ar1 -0.086149 0.000122 -7.0664e+02 0.000000 omega 0.000618 0.000411 1.5062e+00 0.132023 alpha1 0.090424 0.010405 8.6908e+00 0.000000 beta1 0.916128 0.010687 8.5724e+01 0.000000 gamma1 1.000000 0.000000 2.5738e+06 0.000000 delta 0.844145 0.130924 6.4476e+00 0.000000 skew 0.833679 0.028852 2.8895e+01 0.000000 shape 7.325115 1.542399 4.7492e+00 0.000002 Robust Standard Errors: Estimate Std. Error t value Pr(>|t|) mu 0.000197 NaN NaN NaN ar1 -0.086149 NaN NaN NaN omega 0.000618 NaN NaN NaN alpha1 0.090424 NaN NaN NaN beta1 0.916128 NaN NaN NaN gamma1 1.000000 NaN NaN NaN delta 0.844145 NaN NaN NaN skew 0.833679 NaN NaN NaN shape 7.325115 NaN NaN NaN LogLikelihood : 4133.434 Information Criteria ------------------------------------ Akaike -6.0167 Bayes -5.9824 Shibata -6.0168 Hannan-Quinn -6.0038 Q-Statistics on Standardized Residuals ------------------------------------ statistic p-value Lag10 11.45 0.2459 Lag15 16.60 0.2780 Lag20 18.74 0.4737 H0 : No serial correlation Q-Statistics on Standardized Squared Residuals ------------------------------------ statistic p-value Lag10 29.72 0.0004892 Lag15 33.15 0.0027369 Lag20 36.37 0.0094979 ARCH LM Tests ------------------------------------ Statistic DoF P-Value ARCH Lag[2] 15.81 2 0.0003695 ARCH Lag[5] 16.98 5 0.0045286 ARCH Lag[10] 30.99 10 0.0005890 Nyblom stability test ------------------------------------ Joint Statistic: NA Individual Statistics: mu 0.2380 ar1 0.2163 omega 0.1923 alpha1 0.1939 beta1 0.2190 gamma1 NA delta 0.2084 skew 0.1054 shape 0.2543 Asymptotic Critical Values (10% 5% 1%) Joint Statistic: 2.1 2.32 2.82 Individual Statistic: 0.35 0.47 0.75 Sign Bias Test ------------------------------------ t-value prob sig Sign Bias 0.3575 0.720737 Negative Sign Bias 2.5732 0.010180 ** Positive Sign Bias 2.7813 0.005489 *** Joint Effect 14.4861 0.002313 *** Adjusted Pearson Goodness-of-Fit Test: ------------------------------------ group statistic p-value(g-1) 1 20 30.47 0.046075 2 30 40.31 0.078949 3 40 54.67 0.049050 4 50 74.99 0.009861 Elapsed time : 5.466 > summary(GA3) Title: GARCH Modelling Call: garchFit(formula = ~arma(1, 0) + aparch(1, 1), data = last(SPY.log.ret, 1371), cond.dist = "sstd") Mean and Variance Equation: data ~ arma(1, 0) + aparch(1, 1) <environment: 0x000000000e8e8e68> [data = last(SPY.log.ret, 1371)] Conditional Distribution: sstd Coefficient(s): mu ar1 omega alpha1 gamma1 beta1 0.00022015 -0.08726888 0.00039220 0.09300673 0.99999999 0.90917036 delta skew shape 0.95108469 0.83598044 7.13436954 Std. Errors: based on Hessian Error Analysis: Estimate Std. Error t value Pr(>|t|) mu 2.202e-04 2.702e-04 0.815 0.415301 ar1 -8.727e-02 2.557e-02 -3.413 0.000643 *** omega 3.922e-04 9.879e-05 3.970 7.19e-05 *** alpha1 9.301e-02 1.157e-02 8.035 8.88e-16 *** gamma1 1.000e+00 1.085e-02 92.183 < 2e-16 *** beta1 9.092e-01 1.112e-02 81.759 < 2e-16 *** delta 9.511e-01 1.667e-01 5.705 1.16e-08 *** skew 8.360e-01 3.064e-02 27.284 < 2e-16 *** shape 7.134e+00 1.543e+00 4.625 3.75e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Log Likelihood: 4131.182 normalized: 3.013262 Description: Wed Jun 13 14:57:49 2012 by user: cora Standardised Residuals Tests: Statistic p-Value Jarque-Bera Test R Chi^2 1584.761 0 Shapiro-Wilk Test R W 0.9597795 0 Ljung-Box Test R Q(10) 12.32339 0.2639963 Ljung-Box Test R Q(15) 16.8469 0.3280988 Ljung-Box Test R Q(20) 18.48151 0.5557211 Ljung-Box Test R^2 Q(10) 9.478356 0.4873852 Ljung-Box Test R^2 Q(15) 12.33782 0.6532996 Ljung-Box Test R^2 Q(20) 13.34997 0.8618686 LM Arch Test R TR^2 29.52316 0.003292551 Information Criterion Statistics: AIC BIC SIC HQIC -6.013395 -5.979106 -6.013480 -6.000563 |
|
Marco,
1. Use: GAA3=ugarchfit(spec=modeltofit,data=last(SPY.log.ret,1371), fit.control=list(scale=1)) This should get a better result so that the evaluation of the robust estimates does not fail. 2. Likelihoods are very close but omega and their s.e. is somewhat different. To better compare the results use the coefficients from the 2 fits in rugarch: spec1 = modeltofit setfixed(spec1)<-as.list(coef(GA3)) spec2 = modeltofit setfixed(spec2)<-as.list(coef(GAA3)) fit1 = ugarchfit(spec1, last(SPY.log.ret,1371), fit.control=list(fixed.se=1)) fit2 = ugarchfit(spec2, last(SPY.log.ret,1371), fit.control=list(fixed.se=1)) round(cbind(coef(fit1), coef(fit2)),4) fGarch rugarch mu 0.0002 0.0002 ar1 -0.0873 -0.0861 omega 0.0004 0.0006 alpha1 0.0930 0.0904 beta1 0.9092 0.9161 gamma1 1.0000 1.0000 delta 0.9511 0.8431 skew 0.8360 0.8337 shape 7.1344 7.3343 Look at their long run sigma: sqrt(uncvariance(fit1)) 0.01391264 sqrt(uncvariance(fit2)) 0.01378647 As i said in the earlier email, differences are likely related to the gamma parameter hitting its limit, but will investigate some alternate strategies for the omega coefficient scaling when time permits. 3. I don't really understand what you want to do. If you just want the long run unconditional forecast then extract the coefficients from each fit: cf = as.data.frame(volforecast, which = "coefmat", refit=2) cfnames = rownames(cf) cf = cf[,1] names(cf)=cfnames spec = modeltofit setfixed(spec)<-as.list(cf) uncvariance(spec) sigma=as.data.frame(volforecast,which="sigma") Is correct. It returns a n.ahead x n.roll matrix. For the time being, it only support n.ahead<=refit.every. If you want to create long run custom type forecasts just wrap your own ugarchfit+ugarchforecast function (after all that is all that ugarchroll does). Read the documentation on the proper use of the "out.sample" option. 4. NO. The forecast date shown is the ACTUAL future forecast date (since this is an out.of sample rolling forecast for which dates exists). In the ugarchforecast method, when there are no out.sample dates to draw from, the program generates actual future forecast dates (not taking into account holidays etc). -Alexios On 13/06/2012 14:13, Belgarath wrote: > Hello Alexios, > > thank you for the quick reply! Apologies but yesterday yahoo finance was not > working so could not follow up with an appropriate reproducible example: > > 1) > ---- > getSymbols("^GSPC", src="yahoo") > SPY.log.ret=ClCl(GSPC) > GA3=garchFit(formula=~arma(1,0)+aparch(1,1),data=last(SPY.log.ret,1371),cond.dist="sstd") > summary(GA3) > modeltofit=ugarchspec(variance.model = list(model = "apARCH", garchOrder = > c(1, 1), > submodel = NULL, external.regressors = NULL, > variance.targeting = FALSE), > mean.model = list(armaOrder = c(1, 0), include.mean = > TRUE, archm = FALSE, > archpow = 1, arfima = FALSE, external.regressors = NULL, > archex = FALSE), > distribution.model = "sstd", start.pars = list(), > fixed.pars = list()) > > GAA3=ugarchfit(spec=modeltofit,data=last(SPY.log.ret,1371)) > show(GAA3) > volforecast=ugarchroll(spec=modeltofit,data=last(SPY.log.ret,1371), n.ahead > = 21, > forecast.length = 420, refit.every = 21) > sigma=as.data.frame(volforecast,which="density",n.ahead=21) > sigmat <- as.POSIXct(strptime(sigma[,1],format="%Y-%m-%d")) > sigma2 <- xts(sigma[,3],order.by=sigmat)*100*sqrt(252) > plot(sigma2) > --- > > Detailed results are below, but to reply to your points: > 2) rugarch omega is 0.000618 t:1.5062e+00 p:0.132023 while fGarch omega > is 3.922e-04 t:3.970 p:7.19e-05 which is more significant. > > 3) Is the code above usage correct to extract the forecasts? I tried to use > the sigma=as.data.frame(volforecast, which = "sigma") but it only return the > first 21 forecasts. How do I extract the long term mean of the st dev? > > 4) I have one more question: the dates in the > sigma=as.data.frame(volforecast,which="density",n.ahead=21) are alligned > with the date the forecast refers to no the date the forcast is made (ie. it > will be delayed by 21 days in a chart) correct? > > Thank you again for the help and the package! > Marco > > > > ***************** >> show(GAA3) > > *---------------------------------* > * GARCH Model Fit * > *---------------------------------* > > Conditional Variance Dynamics > ----------------------------------- > GARCH Model : apARCH(1,1) > Mean Model : ARFIMA(1,0,0) > Distribution : sstd > > Optimal Parameters > ------------------------------------ > Estimate Std. Error t value Pr(>|t|) > mu 0.000197 0.000007 2.7154e+01 0.000000 > ar1 -0.086149 0.000122 -7.0664e+02 0.000000 > omega 0.000618 0.000411 1.5062e+00 0.132023 > alpha1 0.090424 0.010405 8.6908e+00 0.000000 > beta1 0.916128 0.010687 8.5724e+01 0.000000 > gamma1 1.000000 0.000000 2.5738e+06 0.000000 > delta 0.844145 0.130924 6.4476e+00 0.000000 > skew 0.833679 0.028852 2.8895e+01 0.000000 > shape 7.325115 1.542399 4.7492e+00 0.000002 > > Robust Standard Errors: > Estimate Std. Error t value Pr(>|t|) > mu 0.000197 NaN NaN NaN > ar1 -0.086149 NaN NaN NaN > omega 0.000618 NaN NaN NaN > alpha1 0.090424 NaN NaN NaN > beta1 0.916128 NaN NaN NaN > gamma1 1.000000 NaN NaN NaN > delta 0.844145 NaN NaN NaN > skew 0.833679 NaN NaN NaN > shape 7.325115 NaN NaN NaN > > LogLikelihood : 4133.434 > > Information Criteria > ------------------------------------ > > Akaike -6.0167 > Bayes -5.9824 > Shibata -6.0168 > Hannan-Quinn -6.0038 > > Q-Statistics on Standardized Residuals > ------------------------------------ > statistic p-value > Lag10 11.45 0.2459 > Lag15 16.60 0.2780 > Lag20 18.74 0.4737 > > H0 : No serial correlation > > Q-Statistics on Standardized Squared Residuals > ------------------------------------ > statistic p-value > Lag10 29.72 0.0004892 > Lag15 33.15 0.0027369 > Lag20 36.37 0.0094979 > > ARCH LM Tests > ------------------------------------ > Statistic DoF P-Value > ARCH Lag[2] 15.81 2 0.0003695 > ARCH Lag[5] 16.98 5 0.0045286 > ARCH Lag[10] 30.99 10 0.0005890 > > Nyblom stability test > ------------------------------------ > Joint Statistic: NA > Individual Statistics: > mu 0.2380 > ar1 0.2163 > omega 0.1923 > alpha1 0.1939 > beta1 0.2190 > gamma1 NA > delta 0.2084 > skew 0.1054 > shape 0.2543 > > Asymptotic Critical Values (10% 5% 1%) > Joint Statistic: 2.1 2.32 2.82 > Individual Statistic: 0.35 0.47 0.75 > > Sign Bias Test > ------------------------------------ > t-value prob sig > Sign Bias 0.3575 0.720737 > Negative Sign Bias 2.5732 0.010180 ** > Positive Sign Bias 2.7813 0.005489 *** > Joint Effect 14.4861 0.002313 *** > > > Adjusted Pearson Goodness-of-Fit Test: > ------------------------------------ > group statistic p-value(g-1) > 1 20 30.47 0.046075 > 2 30 40.31 0.078949 > 3 40 54.67 0.049050 > 4 50 74.99 0.009861 > > > Elapsed time : 5.466 > >> summary(GA3) > > Title: > GARCH Modelling > > Call: > garchFit(formula = ~arma(1, 0) + aparch(1, 1), data = last(SPY.log.ret, > 1371), cond.dist = "sstd") > > Mean and Variance Equation: > data ~ arma(1, 0) + aparch(1, 1) > <environment: 0x000000000e8e8e68> > [data = last(SPY.log.ret, 1371)] > > Conditional Distribution: > sstd > > Coefficient(s): > mu ar1 omega alpha1 gamma1 beta1 > 0.00022015 -0.08726888 0.00039220 0.09300673 0.99999999 0.90917036 > delta skew shape > 0.95108469 0.83598044 7.13436954 > > Std. Errors: > based on Hessian > > Error Analysis: > Estimate Std. Error t value Pr(>|t|) > mu 2.202e-04 2.702e-04 0.815 0.415301 > ar1 -8.727e-02 2.557e-02 -3.413 0.000643 *** > omega 3.922e-04 9.879e-05 3.970 7.19e-05 *** > alpha1 9.301e-02 1.157e-02 8.035 8.88e-16 *** > gamma1 1.000e+00 1.085e-02 92.183 < 2e-16 *** > beta1 9.092e-01 1.112e-02 81.759 < 2e-16 *** > delta 9.511e-01 1.667e-01 5.705 1.16e-08 *** > skew 8.360e-01 3.064e-02 27.284 < 2e-16 *** > shape 7.134e+00 1.543e+00 4.625 3.75e-06 *** > --- > Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > > Log Likelihood: > 4131.182 normalized: 3.013262 > > Description: > Wed Jun 13 14:57:49 2012 by user: cora > > > Standardised Residuals Tests: > Statistic p-Value > Jarque-Bera Test R Chi^2 1584.761 0 > Shapiro-Wilk Test R W 0.9597795 0 > Ljung-Box Test R Q(10) 12.32339 0.2639963 > Ljung-Box Test R Q(15) 16.8469 0.3280988 > Ljung-Box Test R Q(20) 18.48151 0.5557211 > Ljung-Box Test R^2 Q(10) 9.478356 0.4873852 > Ljung-Box Test R^2 Q(15) 12.33782 0.6532996 > Ljung-Box Test R^2 Q(20) 13.34997 0.8618686 > LM Arch Test R TR^2 29.52316 0.003292551 > > Information Criterion Statistics: > AIC BIC SIC HQIC > -6.013395 -5.979106 -6.013480 -6.000563 > > > > -- > View this message in context: http://r.789695.n4.nabble.com/rugarch-and-fGarch-tp4633077p4633253.html > Sent from the Rmetrics mailing list archive at Nabble.com. > > _______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions should go. > _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. |
|
Hello Alexios,
thank you very much! With the fit.control=list(scale=1) is also much faster. I also added the multi-core support, is there any other way to improve the performance? Thank you very much! Marco |
|
Marco,
All models (more precisely their filters which are used in the estimation process) in the rugarch package are already coded in C for speed. The "apARCH" is an omnibus model and as such carries a penalty for such flexibility, as does the use of the 'sstd' distribution. There is also a small penalty for the 1-stage estimation of ARFIMA-GARCH, rather than the marginally faster 2 stage estimation which I do not make use of in the package (but you can control for that by passing an arima filtered residual series using an appropriate specification and reconstituting later with fixed parameters in the spec for doing forecasting). For the rolling estimation, you can make use of the parallel option to evaluate in parallel the rolling estimations/forecasts. See the FAQ section of the vignette for some comments on the tradeoff between the number of cores to use versus the size of the problem for the snowfall package. I have personally found that running things on linux with the multicore package is quite faster, but that may be because I do not have any optimized setup for windows R. -Alexios On 14/06/2012 13:23, Belgarath wrote: > Hello Alexios, > > thank you very much! > > With the fit.control=list(scale=1) is also much faster. > > I also added the multi-core support, is there any other way to improve the > performance? > > Thank you very much! > Marco > > -- > View this message in context: http://r.789695.n4.nabble.com/rugarch-and-fGarch-tp4633077p4633368.html > Sent from the Rmetrics mailing list archive at Nabble.com. > > _______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions should go. > _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. |
|
Thank you very much Alexios.
One more question, related to my point (4) two messages above, where I probably have not been very clear. Please see the following code. --- getSymbols("^GSPC", src="yahoo") getSymbols("^VIX", src="yahoo") SPY.log.ret=ClCl(GSPC) #GA3=garchFit(formula=~arma(1,0)+aparch(1,1),data=last(SPY.log.ret,1371),cond.dist="sstd") #summary(GA3) modeltofit=ugarchspec(variance.model = list(model = "apARCH", garchOrder = c(1, 1), submodel = NULL, external.regressors = NULL, variance.targeting = FALSE), mean.model = list(armaOrder = c(1, 0), include.mean = TRUE, archm = FALSE, archpow = 1, arfima = FALSE, external.regressors = NULL, archex = FALSE), distribution.model = "sstd", start.pars = list(), fixed.pars = list()) #GAA3=ugarchfit(spec=modeltofit,data=last(SPY.log.ret,1371),fit.control=list(scale=1)) #show(GAA3) volforecast=ugarchroll(spec=modeltofit,data=last(SPY.log.ret,1371), n.ahead = 21, forecast.length = 420, refit.every = 21, fit.control=list(scale=1)) sigma=as.data.frame(volforecast,which="density",n.ahead=21) sigmat <- as.Date(strptime(sigma[,1],format="%Y-%m-%d")) sigma2 <- xts(sigma[,3],order.by=sigmat)*100*sqrt(252) plot(sigma2) lines(Cl(VIX), col="red") sigmat <- as.Date(index(first(last(GSPC,420+21),420))) sigma2 <- xts(sigma[,3],order.by=sigmat)*100*sqrt(252) plot(sigma2) lines(Cl(VIX), col="red") --- As you can see the two are very distant: I think the dates that are passed by the as.data.frame(volforecast,which="density",n.ahead=21) refers to the forecast date (i.e. 2012-05-07 20.7 means the vol is forecasted to be 20.7 on the 2012-05-07) not the date in which the forecast is made (i.e. the forecast for the 21d vol made on the 2012-05-07 is 20.7). I realise I was not very clear in my previous question... So if I instead use --- sigmat2 <- as.Date(index(first(last(GSPC,420+21),420))) sigma3 <- xts(sigma[,3],order.by=sigmat)*100*sqrt(252) plot(sigma3) lines(Cl(VIX), col="red") ---- they are now aligned. So if I want the 21d forecast aligned with the date they have been made I have to go for the second version, correct? In this way thou I missed the last 21 days in the sample, do you think there is a way to get them back? Thank you very much for all the help! Rgds, marco |
|
Please try to make the reproducible examples a little more compact.
As I said in the previous email the dates shown are the dates aligned to the n.ahead forecast. The fact that you do not get the last 21 days is because the rolling method uses only out.sample data i.e. forecasts only up to the available out.sample (see the ugarchforecast function). I also mentioned that n.ahead MUST BE <= refit.every (i.e. n.ahead<=out.sample per refit), and that a change to accommodate the case of n.ahead>refit.every might come in due course. The point of using the rolling function is for backtesting models for which you need realized (i.e. out.sample) data to do so. I will again urge you to wrap your own function which makes use of the ugarchfit+ugarchforecast functions if you want more customization. -Alexios On 14/06/2012 19:07, Belgarath wrote: > Thank you very much Alexios. > > One more question, related to my point (4) two messages above, where I > probably have not been very clear. Please see the following code. > > --- > getSymbols("^GSPC", src="yahoo") > getSymbols("^VIX", src="yahoo") > SPY.log.ret=ClCl(GSPC) > #GA3=garchFit(formula=~arma(1,0)+aparch(1,1),data=last(SPY.log.ret,1371),cond.dist="sstd") > #summary(GA3) > modeltofit=ugarchspec(variance.model = list(model = "apARCH", garchOrder = > c(1, 1), > submodel = NULL, external.regressors = NULL, > variance.targeting = FALSE), > mean.model = list(armaOrder = c(1, 0), include.mean = > TRUE, archm = FALSE, > archpow = 1, arfima = FALSE, external.regressors = NULL, > archex = FALSE), > distribution.model = "sstd", start.pars = list(), > fixed.pars = list()) > > #GAA3=ugarchfit(spec=modeltofit,data=last(SPY.log.ret,1371),fit.control=list(scale=1)) > #show(GAA3) > volforecast=ugarchroll(spec=modeltofit,data=last(SPY.log.ret,1371), n.ahead > = 21, > forecast.length = 420, refit.every = 21, > fit.control=list(scale=1)) > sigma=as.data.frame(volforecast,which="density",n.ahead=21) > sigmat <- as.Date(strptime(sigma[,1],format="%Y-%m-%d")) > sigma2 <- xts(sigma[,3],order.by=sigmat)*100*sqrt(252) > plot(sigma2) > lines(Cl(VIX), col="red") > > sigmat <- as.Date(index(first(last(GSPC,420+21),420))) > sigma2 <- xts(sigma[,3],order.by=sigmat)*100*sqrt(252) > > plot(sigma2) > lines(Cl(VIX), col="red") > > --- > > As you can see the two are very distant: I think the dates that are passed > by the as.data.frame(volforecast,which="density",n.ahead=21) refers to the > forecast date (i.e. 2012-05-07 20.7 means the vol is forecasted to be > 20.7 on the 2012-05-07) not the date in which the forecast is made (i.e. the > forecast for the 21d vol made on the 2012-05-07 is 20.7). I realise I was > not very clear in my previous question... > > So if I instead use > > --- > sigmat2 <- as.Date(index(first(last(GSPC,420+21),420))) > sigma3 <- xts(sigma[,3],order.by=sigmat)*100*sqrt(252) > > plot(sigma3) > lines(Cl(VIX), col="red") > > ---- > > they are now aligned. > > So if I want the 21d forecast aligned with the date they have been made I > have to go for the second version, correct? > > In this way thou I missed the last 21 days in the sample, do you think there > is a way to get them back? > > Thank you very much for all the help! > Rgds, > marco > > > > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/rugarch-and-fGarch-tp4633077p4633432.html > Sent from the Rmetrics mailing list archive at Nabble.com. > > _______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions should go. > _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. |
| Powered by Nabble | Edit this page |
