0

I found the following code by mister Eric Zivot (https://faculty.washington.edu/ezivot/econ589/econ589multivariateGarch.r).

Could anyone help me, here, in the code, we have only 2 stocks for DCC GACH 1,1 - if I do have, for instance, 100-200 stocks, could I, somehow, run the code to check automatically all possible pairs.

Thanks, Markus

marbel
  • 7,560
  • 6
  • 49
  • 68
Markus
  • 11

1 Answers1

1

if you check the code you can see that he used the data "MSFT" and "GSPC". He calculates the returns

MSFT.ret = CalculateReturns(MSFT, method="log")
GSPC.ret = CalculateReturns(GSPC, method="log")

creates the combined series

MSFT.GSPC.ret = merge(MSFT.ret,GSPC.ret)

and fits an univariate GARCH and then the DCC GARCH model

# univariate normal GARCH(1,1) for each series
garch11.spec = ugarchspec(mean.model = list(armaOrder = c(0,0)), 
                          variance.model = list(garchOrder = c(1,1), 
                          model = "sGARCH"), 
                          distribution.model = "norm")

# dcc specification - GARCH(1,1) for conditional correlations
dcc.garch11.spec = dccspec(uspec = multispec( replicate(2, garch11.spec) ), 
                           dccOrder = c(1,1), 
                           distribution = "mvnorm")
dcc.garch11.spec

dcc.fit = dccfit(dcc.garch11.spec, data = MSFT.GSPC.ret)

Here you can change "MSFT" and "GSPC" and if you need help to write for example a loop to iterate over all combinations, post a simple code with your data.frame or matrix with the data and a simple example.

Triss
  • 561
  • 3
  • 11
  • Thanks Triss, yes, so this guy makes a merged pair of two units, so, for example, I do have AAPL, GOOG, MSFT, MS. So here is 4 stocks, so we can automatically merge all of them by symbol.vec =c("AAPL","GOOG","MSFT","MS") e <- new.env() getSymbols(symbol.vec, from ="2010-01-03", to = "2020-03-19", env = e) pframe <- do.call(merge, as.list(e)) head(pframe) pframe.ret = CalculateReturns(pframe, method="log") pframe.ret = pframe.ret[-1,] but afterwards, do we have any chance to automatically run all pairs through the below code, avoiding copy-pasting of a particular ticker? – Markus Mar 26 '20 at 07:48