R

R 上的 MSGARCH 包

  • October 1, 2016

我在 R 上使用 MSGARCH 包來擬合馬爾可夫切換 GARCH 模型。我使用 fit.MLE(即標準最大概似法)擬合 GARCH 模型,使用三種方案。參數由向量估計和給出:

$ \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) $ .

j在哪裡 $ \alpha_{ij} $ , $ \beta_{j} $ 表示狀態。輸出的 $ P_i $ 只有六個元素並且具有負值。它不是轉換機率矩陣中預期的九個元素。有誰知道這是什麼?或者如何查找正確的矩陣 $ P $ ?

這是輸出上述向量的程式碼(importsnp 是一系列對數返回):

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

要獲得更易讀的擬合輸出,您可以使用函式 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

如果您只想輸出轉換矩陣,您可以使用:

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

有 6 個參數,因為其他 3 個是多餘的,因為它是 1 減去與同一狀態相關的其他機率的總和。

負值是剛剛在開發版本中修復的一個錯誤,當狀態數大於 2 時,將參數向量轉換為轉移矩陣的函式不正確。另外,有時我們會在優化器沒有的情況下得到負值收斂。我們對優化方案進行了更改,以盡可能避免這種情況。您可以在 Github 上下載開發版本的原始碼或壓縮包。它很快就會出現在 CRAN 上。

引用自:https://quant.stackexchange.com/questions/30348