You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言中MSGARCH包如何像rugarch设定均值方程外部回归变量?

Adding External Regressors to the Mean Equation in MSGARCH

Great question! Moving from rugarch to MSGARCH (for regime-switching or standard GARCH models) means adjusting to a slightly different specification structure, but adding external regressors to the mean equation is straightforward once you know where to look.

Key Difference from rugarch

In rugarch, you specify mean equation regressors inside the mean.model$external.regressors argument of ugarchspec(). In MSGARCH, the equivalent setting lives within the mean.spec list passed to the CreateSpec() function—this is the core spot to target.

Step-by-Step Implementation

Here’s a concrete, reproducible example to walk you through the process:

  1. Load the package and prepare your data
    First, load MSGARCH and create your time series returns + external regressor matrix (each column is a separate regressor, and rows must match the length of your returns data):

    library(MSGARCH)
    
    # Replace with your actual returns data
    returns <- rnorm(100)
    
    # Create external regressors (2 regressors for 100 observations)
    external_regs <- matrix(rnorm(100 * 2), ncol = 2, dimnames = list(NULL, c("macro_reg", "firm_reg")))
    
  2. Define the MSGARCH specification
    Use CreateSpec() to build your model, and plug in the external regressors directly in the mean.spec list:

    spec <- CreateSpec(
      # Match your sGARCH(1,1) variance setup from rugarch
      variance.spec = list(model = "sGARCH", garchOrder = c(1, 1)),
      # Mean model with ARMA(1,1) + external regressors
      mean.spec = list(
        model = "ARMA",
        armaOrder = c(1, 1),
        include.mean = TRUE,  # Keeps the intercept in the mean equation
        external.regressors = external_regs  # Your regressors go here
      ),
      # Match your normal distribution setting
      distribution.spec = list(distribution = "norm"),
      # Disable regime switching if you don't need it (set to TRUE for multi-regime models)
      switch.spec = list(do.mix = FALSE)
    )
    
  3. Fit the model and inspect results
    Estimate the model with FitML() and check the summary to confirm your regressor coefficients are included in the mean equation output:

    fit <- FitML(spec = spec, data = returns)
    summary(fit)
    

Critical Details to Keep in Mind

  • Regressor Format: external.regressors requires a matrix (not a data frame or vector). Double-check that the number of rows exactly matches your returns data length to avoid errors.
  • Regime Switching Support: If you’re building a multi-regime model (switch.spec = list(do.mix = TRUE)), use the switch.mean parameter in switch.spec to control whether regressor coefficients vary across regimes: set switch.mean = TRUE for regime-specific coefficients, or FALSE to share coefficients across regimes.
  • Mean Equation Flexibility: If you set include.mean = FALSE, the mean equation will omit the intercept and only include ARMA terms + external regressors.

内容的提问来源于stack exchange,提问作者Markoff Chainz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:19:46