咨询在Tsay的GARCH-in-Mean代码中添加dummy variable的位置以测试其影响
First, let's break down where to insert dummy variables based on what effect you want to test (mean equation vs. variance equation) — since the GARCH-in-Mean (GARCH-M) model has two core components: the mean equation (which includes the conditional variance term) and the variance (GARCH) equation.
1. Prepare Your Dummy Variable
First, define your dummy variable (e.g., a 0-1 vector for event periods) to match the length of your return series (rt in the original code). For example:
# Example: Dummy = 1 for periods 50-100 (event window), 0 otherwise dummy <- rep(0, length(rt)) dummy[50:100] <- 1
2. Add Dummy to the Mean Equation (Test Impact on Returns/GARCH-M Effect)
If you want to test whether the dummy affects average returns (or interacts with the GARCH-M term), modify the mean.model argument in ugarchspec to include the dummy as an external regressor. This inserts the dummy directly into the mean equation:
# Modified specification with dummy in mean equation spec <- ugarchspec( variance.model = list(garchOrder = c(1,1)), mean.model = list( armaOrder = c(0,0), archm = TRUE, # Keeps the GARCH-in-Mean term enabled archpow = 1, external.regressors = as.matrix(dummy) # Insert dummy here ) ) # Fit the updated model fit <- ugarchfit(spec = spec, data = rt)
After fitting, run summary(fit) to check the dummy's coefficient significance — a small p-value means the dummy has a meaningful impact on the mean return alongside the GARCH-M term.
If you want to test an interaction between the dummy and the GARCH-M term, create an interaction variable and add it to the external regressors:
# Create interaction term: dummy * conditional volatility proxy # (Use sigma from an initial basic GARCH-M fit for this example) basic_fit <- ugarchfit(ugarchspec(variance.model = list(garchOrder = c(1,1)), mean.model = list(armaOrder = c(0,0), archm = TRUE)), data = rt) interact_term <- dummy * sqrt(basic_fit@fit$sigma2) # Update spec with both dummy and interaction term spec_interact <- ugarchspec( variance.model = list(garchOrder = c(1,1)), mean.model = list( armaOrder = c(0,0), archm = TRUE, archpow = 1, external.regressors = cbind(dummy, interact_term) ) ) fit_interact <- ugarchfit(spec = spec_interact, data = rt)
3. Add Dummy to the Variance Equation (Test Impact on Volatility)
To test if the dummy affects volatility dynamics (the GARCH component), add the dummy to the variance.model instead:
# Modified specification with dummy in variance equation spec_vol <- ugarchspec( variance.model = list( garchOrder = c(1,1), external.regressors = as.matrix(dummy) # Insert dummy here ), mean.model = list( armaOrder = c(0,0), archm = TRUE, archpow = 1 ) ) fit_vol <- ugarchfit(spec = spec_vol, data = rt)
Check the variance equation coefficients in summary(fit_vol) — a significant dummy coefficient means the event captured by the dummy changes the volatility behavior of the series.
Key Notes
- Ensure your dummy variable has no missing values and matches the length of your return data exactly.
- For multiple dummies, pass a matrix (e.g.,
cbind(dummy1, dummy2)) toexternal.regressors. - Run diagnostic tests (like ARCH tests on residuals) to confirm the model still fits well after adding the dummy.
内容的提问来源于stack exchange,提问作者NSF

