I use R to estimate a Multivariate GARCH(1,1) model for 4 time series. I tried it with the rmgarch package. Seems like I'm using it wrong but I don't know what my mistake is. First time using.
library(quantmod)
library(fBasics)
library(rmgarch)
#load data, time series closing prices, 10 year sample
#DAX 30
getSymbols('^GDAXI', src='yahoo', return.class='ts',from="2005-01-01", to="2015-01-31")
GDAXI.DE=GDAXI[ , "GDAXI.Close"]
#S&P 500
getSymbols('^GSPC', src='yahoo', return.class='ts',from="2005-01-01", to="2015-01-31")
GSPC=GSPC[ , "GSPC.Close"]
#Credit Suisse Commodity Return Strat I
getSymbols('CRSOX', src='yahoo', return.class='ts',from="2005-01-01", to="2015-01-31")
CRSOX=CRSOX[ , "CRSOX.Close"]
#iShares MSCI Emerging Markets
getSymbols('EEM', src='yahoo', return.class='ts',from="2005-01-01", to="2015-01-31")
EEM=EEM[ , "EEM.Close"]
#calculating log returns of the time series
log_r1=diff(log(GDAXI.DE[39:2575]))
log_r2=diff(log(GSPC))
log_r3=diff(log(CRSOX))
log_r4=diff(log(EEM))
#return vector
r_t=cbind(log_r1, log_r2,log_r3, log_r4)
#specifying and fitting the model
model = multispec(replicate(4, ugarchspec(variance.model = c(1,1))))
model_order = mgarchspec(model, Order = c(1, 1), distribution ='mvnorm')
fit = mgarchfit(model_order, data = r_t, solver = 'solnp',fit.control = list(eval.se = TRUE))
print(fit.1)
below you will find a parallel implementation of a multivariate DCC and ADCC Garch models. It is unclear what you are trying to achieve, but I assume you are looking for some kind of correlation between each of the variables. Or at least an uncorrelated measure of volatility. My code is based on code that can be found here:"Multivariate Garch implementation". I highly recommend reading this.
Load all your series as before
library(rmgarch)
library(parallel)
library(quantmod)
Ensure equal length of your data and calculate log returns of the time series
Dat<-data.frame(GDAXI.DE[-c(1:22)],GSPC,CRSOX,EEM)
Dat<-apply(Dat,2,function(x) Delt(x,k=1,type="log"))
Specify your univariate garch process along with your multivariate model. Here I include both the vanilla DCC-GARCH as well as the assymmetric DCC-GARCH model specification
xspec = ugarchspec(mean.model = list(armaOrder = c(1, 1)), variance.model = list(garchOrder = c(1,1), model = 'sGARCH'), distribution.model = 'norm')
uspec = multispec(replicate(4, xspec))
spec1 = dccspec(uspec = uspec, dccOrder = c(1, 1), distribution = 'mvnorm')
spec1a = dccspec(uspec = uspec, dccOrder = c(1, 1), model='aDCC', distribution = 'mvnorm')
When performing computationally intense models, I recommend using a parallel approach. Luckily rmgarch
has this feature build in. So, lets open the number of clusters we want to perform the analysis on
cl = makePSOCKcluster(4)
multf = multifit(uspec, Dat, cluster = cl)
We can now finally fit the model
fit1 = dccfit(spec1, data = Dat, fit.control = list(eval.se = TRUE), fit = multf, cluster = cl)
fit_adcc = dccfit(spec1, data = Dat, fit.control = list(eval.se = TRUE), fit = multf, cluster = cl)
print(fit1)
print(fit_adcc)
It is important to remember to close your clusters using
stopCluster(cl)
I hope this helps you in what you are looking for!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With