* * Copula.rpf * Demonstrates use of a copula as an alternative to a multivariate GARCH model * open data g10xrate.xls data(format=xls,org=columns) 1 6237 usxjpn usxfra usxsui * compute nvar=2 * set xfra = 100.0*log(usxfra/usxfra{1}) set xsui = 100.0*log(usxsui/usxsui{1}) * * Use AR(1) models for the means * equation eqfra xfra # constant xfra{1} equation eqsui xsui # constant xsui{1} group mvar1 eqfra eqsui * * For copula, standardize with univariate student-t GARCH models with univariate * AR(1) mean models. * garch(p=1,q=1,equation=eqfra,hseries=hfra,distrib=t) * * Standardized residuals * set zfra = %resids/sqrt(hfra) * * Empirical distribution of standardized residuals * order(ranks=rfra) zfra set rfra = rfra/%nobs * * Marginal distribution given the estimated t distribution. fixt is to correct for * the fact that GARCH models model the variance of the distribution, not the * variance of the underlying Normal. * compute nufra=%shape compute fixt=(nufra-2)/nufra set mfra = %tcdf(zfra/sqrt(fixt),nufra) * garch(p=1,q=1,equation=eqsui,hseries=hsui) set zsui = %resids/sqrt(hsui) order(ranks=rsui) zsui set rsui = rsui/%nobs compute nusui=%shape compute fixt=(nusui-2)/nusui set msui = %tcdf(zsui/sqrt(fixt),nusui) * * Gaussian copula estimation * * Parameterize subdiagonal * dec packed[real] qsub(nvar-1,nvar-1) compute qsub=%const(0.0) * function %subtocorr sub type packed sub type symm %subtocorr local integer i j * dim %subtocorr(%rows(sub)+1,%rows(sub)+1) ewise %subtocorr(i,j)=%if(i==j,1.0,sub(i-1,j)) end * * This should be almost identical to a CC model with Normal residuals. (The * difference is because the CC model does joint estimates of all parameters). * frml gcopula = %logdensity(%subtocorr(qsub),||zfra,zsui||) nonlin qsub maximize gcopula * * Student t copula estimation * compute nu=10.0 * frml tcopula = %logtdensitystd(%subtocorr(qsub),||zfra,zsui||,nu) nonlin qsub nu maximize tcopula * * CML estimation * * Gaussian copula CML estimator * nonlin qsub frml gcopula_cml = %logdensity(%subtocorr(qsub),||%invnormal(rfra),%invnormal(rsui)||) maximize gcopula * * Bivariate Gumbel CML estimator * compute theta=1.0 nonlin theta frml gumbel_cml = -(theta+1)*(log(rfra)+log(rsui))-(1.0/theta+2)*log(rfra^-theta+rsui^-theta) maximize gumbel_cml * * Gumbel estimator using t marginals with degrees of freedom from GARCH model * frml gumbel_eml = -(theta+1)*(log(mfra)+log(msui))-(1.0/theta+2)*log(mfra^-theta+msui^-theta) maximize gumbel_eml * compute ndraws=10000 clear(length=ndraws) xxfra xxsui do draw=1,ndraws compute u=%uniform(0.0,1.0) compute p=%uniform(0.0,1.0) compute v=((p^-(theta/(theta+1))-1)*u^(-theta)+1)^(-1.0/theta) * * Back-transform using the t-distribution * compute dfra=%invtcdf(u,nufra) compute dsui=%invtcdf(v,nufra) * * Back transform using the variances at the final entry. * compute dfra=dfra*sqrt(hfra(6237)*(nufra-2)/nufra) compute dsui=dsui*sqrt(hsui(6237)*(nusui-2)/nusui) compute xxfra(draw)=dfra compute xxsui(draw)=dsui end do draw * * The draws are much more correlated in the left tail than the right tail * scatter(hlabel="France",vlabel="Switzerland",footer="Copula simulation of distribution") # xxfra xxsui