# MSGARCH package on R

I am using the MSGARCH package on R to fit a Markov switching GARCH model. I fit the GARCH model using fit.MLE (so standard Maximum Likelihood), using three regimes. The parameters are estimated and given by the vector:

$\theta = (\alpha_{11}, \alpha_{12}, \alpha_{13}, \alpha_{21}, \alpha_{22}, \alpha_{23}, \beta_{1}, \beta_{2}, \beta_{3}, P_{1}, P_{2}, P_{2}, P_{4}, P_5, P_6)$.

Where the j in $\alpha_{ij}$, $\beta_{j}$ denotes the state. The outputed $P_i$ is only six elements and with negative values. Its not the expected nine elements from the transition Probability matrix. Does anyone know what this is? Or how to lookup the correct matrix $P$?

Here is the code for outputing the vector above (importsnp is a series of log-returns):

require(MSGARCH)

library(coda)

snp <- as.matrix(importsnp)*100

spec <- MSGARCH::create.spec(model = c("sGARCH","sGARCH","sGARCH"),
distribution = c("norm","norm","norm"),
do.skew = c(FALSE,FALSE,FALSE),
do.mix = FALSE,
do.shape.ind = FALSE)
set.seed(123)

fit <- MSGARCH::fit.mle(spec = spec, y = snp)

theta <- fit$theta • Welcome to Quant.SE. It would be helpful if you could provide your code and output and specify exactly what you try to achieve and where the problem is. – vonjd Sep 28 '16 at 18:21 • This is a lot better, it would be good to add code that creates the returns (the importsnp variable) but I hope this is answerable now. – Bob Jansen Sep 29 '16 at 7:41 • Importsnp is just an arbitrary series. The issue I am still having is with the output object$\theta\$. – Melly Donald Sep 29 '16 at 17:21

For a more readable output of the fit you can use the function summary():

require(MSGARCH)

data("sp500")

snp <- as.matrix(sp500)

spec <- MSGARCH::create.spec(model = c("sGARCH","sGARCH","sGARCH"),
distribution = c("norm","norm","norm"),
do.skew = c(FALSE,FALSE,FALSE),
do.mix = FALSE,
do.shape.ind = FALSE)
set.seed(123)

fit <- MSGARCH::fit.mle(spec = spec, y = snp, ctr = list(do.init = FALSE, do.enhance.theta0 = TRUE))

summary(fit)
[1] "Specification Type: Markov-Switching"
[1] "Specification Name: sGARCH_normal_sym sGARCH_normal_sym sGARCH_normal_sym"
[1] "Number of parameters in each variance model: 3 3 3"
[1] "Number of parameters in each distribution: 0 0 0"
[1] "Default parameters:"
alpha0_1 alpha1_1 beta_1 alpha0_2 alpha1_2 beta_2 alpha0_3 alpha1_3 beta_3         P         P         P         P
[1,]      0.1      0.1    0.8      0.1      0.1    0.8      0.1      0.1    0.8 0.3333333 0.3333333 0.3333333 0.3333333
P         P
[1,] 0.3333333 0.3333333
[1] "DEoptim initialization: FALSE"
[1] "Fitted Parameters:"
alpha0_1   alpha1_1   beta_1 alpha0_2   alpha1_2    beta_2  alpha0_3  alpha1_3   beta_3       P          P
[1,] 0.0003991736 0.07382696 0.925262    1e-04 0.02250533 0.8543849 0.0848339 0.1587613 0.836886 0.72136 0.03285818
P          P         P         P
[1,] 0.1856006 0.00248085 0.3555367 0.3865909
[1] "Transition matrix:"
t = 1      t = 2     t = 3
t + 1 = 1 0.72135997 0.18560065 0.3555367
t + 1 = 2 0.03285818 0.00248085 0.3865909
t + 1 = 3 0.24578185 0.81191850 0.2578724
[1] "Stable probabilities:"
Stable probabilities
State 1            0.5214967
State 2            0.1460292
State 3            0.3324741
[1] "Unconditional volatility:"
State 1    State 2 State 3
[1,] 0.6619352 0.02850059 4.41474
Log-kernel:  -6517.631
AIC:  13209.02
BIC:  13305.3

If you only want to output the transition matrix you can use:

MSGARCH::transmat(fit)
t = 1      t = 2     t = 3
t + 1 = 1 0.72135997 0.18560065 0.3555367
t + 1 = 2 0.03285818 0.00248085 0.3865909
t + 1 = 3 0.24578185 0.81191850 0.2578724

There are 6 parameters because the other 3 are redundant since it is 1 minus the sum of the other probabilities associated to the same state.

The negative value was a bug that just has been fixed in the development version where the function transforming the parameter vector into the transition matrix was incorrect when the number of states was above 2. Also, we would sometimes obtain negative value when the optimizer did not converge. We made a change to the optimization scheme to avoid this as much as possible. You can download the source code or the tarball of the development version on Github. It will be on CRAN soon.

• Thanks for the demonstration. How to model when the transition probabilities are the function of one or two economic variables? For reference: doi.org/10.1016/j.ememar.2008.02.005 – Polar Bear Nov 28 '17 at 17:15